Misc scripts

Renaming daily/weekly/monthly rsnapshot folders

If something went wrong with rsnapshot, it might be neccessary to remove the last created backup folder. But then you'd have to rename the whole lots again, so that the new last one is called 0. For instance, you have 29 daily backups and remove daily.0. This command will rename 1 to 0, 2 to 1, 3 to 2, etc:

for i in `seq 1 29`; do mv daily.$i daily.`expr $i - 1`; done 

 

Removing old kernels and headers

Because you automatically upgrade your kernels, your VMs get clogged up with old kernels and headers, which can eventually fill up your disk (space wise or inode wise). This is the way to remove all but the running kernel:

visser@cajones:~$ sudo apt-get purge `apt-show-versions | cut -d":" -f 1 | grep -E 'linux-(headers|image(-extra)?)-[0-9]+' | grep -v $(uname -r | sed -E 's/-[a-z]+$//')`

 

 

Removing set of e-mail address from another set of email address

List of address with optional names, separated by whitespace:

visser@rasputin:~$ cat addresses.txt
dick@TIENHUIS.nl  Dick Visser
dnmvisser@Gmail.CoM  Dick "Gmail" Visser
dnmvisser@yahoo.com
dick.visser@geant.org  Dick Visser
visser@terena.org Dick's old address...

Similar for a blacklist:

visser@rasputin:~$ cat blacklist.txt
Dnmvisser@gmail.com  Evil guy

 

You can 'subtract' the blacklist using this Ruby one line:

 

visser@rasputin:~$ ruby -e 'a = File.readlines("addresses.txt").map { |x| x.split.first.downcase } - File.readlines("blacklist.txt").map { |x| x.split.first.downcase }; puts a'
dick@tienhuis.nl
dnmvisser@yahoo.com
dick.visser@geant.org
visser@terena.org