Archive for the ‘Scripts’ Category

rsync like backup to Rackspace Cloud File with duplicity

It seems that there is no much documentation about how to do rsync like backup with duplicty so here it is :

Install python-cloudfiles from here http://github.com/rackspace/python-cloudfiles
Install duplicity, its available directly from Debian or alike distros (ie: ubuntu) or you can do that from source from the homepage.
Get your API Key from https://manage.rackspacecloud.com/ and use a script [...]

Read the rest of this entry »

Upload to Rackspace Cloud files from GNOME nautilus

After seeing this script http://overhrd.com/?p=106 which allow to upload files with the file manager (finder) of MacosX to Rackspace Cloud Files, I have made a nautilus script that doe the same for us Gnome/Unix users.
Available here :
http://github.com/chmouel/nautilus-rackspace-cloud-file/tree/master

Read the rest of this entry »

Using ProxyCommand with OpenSSH and a Bastion server.

So at work we have to use a bastion host for all our connections to servers to be able to get called PCI compliant. This kind of stuff could be a pain to use when you have to use another host to do RSYNC/SCP or other stuff that need direct transfer to workstation.
Thankfully OpenSSH is [...]

Read the rest of this entry »

Generating md5 encrypted password for chpasswd

If you want to generate properly encrypted password to feed to chpasswd, the most easier and proper way is to do that from command line :
[code lang="bash"]
echo "encryptedpassword"|openssl passwd -1 -stdin
[/code]
If you want to generate in pure python you can do it like that :
[code lang="python"]
def md5crypt(password, salt, magic='$1$'):
[...]

Read the rest of this entry »

Automatic best resolution with xrandr

If you like me you have a big screen with your laptop and wants to automate when your X session start to get the best resolution, you can use that script :
[code lang="bash"]
#!/bin/bash
function get_resolutions() {
xrandr|while read -a line;do
RES="${line[1]}x${line[3]} "
[[ ${RES} != [0-9]* ]] && continue
echo ${RES}
done
}
_BEST_RES=0
BEST_RES=
for res in $(get_resolutions);do
_res=${res/x/}
[[ $_res -ge ${_BEST_RES} ]] && {
BEST_RES=${res}
_BEST_RES=${_res}
}
done
xrandr [...]

Read the rest of this entry »

Automate SSH known_hosts cleanup

If you like me, you have to do a lot of installs[1] of the same test machine with the same IP and have to ssh it you will notice this annoying message :
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that [...]

Read the rest of this entry »

SVN Diff against changes in the remote repository.

A useful svn wrapper scripts. Get a diff of your local repostitory against the upstream repository changes. I wonder why it is not builtins though like a svn status -u but for dif.

#!/bin/bash
 
IFS="
"
for line in `svn status -u`;do
[[ $line != " "* ]] && continue
rev=`echo [...]

Read the rest of this entry »

History expansion and substitions in ZSH

I better to keep that somewhere since i always forget that thing, to do a search and replace from the command line in zsh. you just have to do the :s^FOO^BAR after your expansion
For example you just have typed the long command line :

blah bar FOO=1 FOO=3 FOO=6 cnt=1

you can just type :

!blah:s^FOO^VALUE^:G

and it will [...]

Read the rest of this entry »

Get size of Postgres DB from filesystem

Get the size accurately from postgres local filesystem, i guess there is some sql stuff that can do that but that does the job as well for me :

#!/bin/bash
/usr/lib/postgresql/8.1/bin/oid2name -U postgres|while read -a e;do
name=${e[1]}
oid=${e[0]}
[[ $oid == "All" || $oid == "Oid" || -z $oid || -z $name ]] && continue
typeset -a size
size=(`du -s /var/lib/postgresql/8.1/main/base/$oid`)
size=${size[0]}
printf [...]

Read the rest of this entry »

svn diff without spaces

I am sic of spaces and having svn diff that does not get the spaces removed. So here is a simple script that does the stuff that you can use as your diff-cmd :

#!/bin/bash
for i in $@;do
echo $i |grep -q “)” && continue
echo $i |grep -q “(” && continue
t=”$t $i”
done
diff -bBw $t

Read the rest of this entry »