Categories
Uncategorized

Quick data pipeline for encryption and decryption

In the need for a quick pipeline to encrypt and decrypt data, gpg can be quite handy, for example it can be used in this way to encrypt  some backup before transferring it to a third part hosted  storage:

cat backupfile.tgz | gpg -c --cipher-algo=BLOWFISH > backupfile.tgz.gpg

(you’ll be asked for the Passphrase to use for encryption)and for decryption:

cat backupfile.tgz.gpg |gpg -d --cipher-algo=BLOWFISH > backupfile.tgz

(you’ll be obviously asked for the Passphrase again, don’t forget it and save it in a safe place!)To use it inside a script (batch process) the useful --passphrase switch can be employed:

cat backupfile.tgz | gpg -c –cipher-algo=BLOWFISH --passphrase abcdefghi1234567890 > backupfile.tgz.gpg

in this case, do not forget to set 700 the file for avoiding unwanted reading…

Categories
Uncategorized

Clear the whole Postfix mail queue

To clear the whole Postfix mail queue you can use this command:

~# for i in `mailq|grep '@' |awk {'print $1'}|grep -v '@'`; do postsuper -d $i ; done

Thomas Sewell from coolsewell.com contributed with this helpful notes:you could also just do:

postsuper -d ALL

to clear all mail queues or even

postsuper -d ALL deferred

to just get rid of deferred mail from the queue.Thanks Thomas! 🙂

Categories
Uncategorized

Quick System Backup via Netcat

Sometimes a backup is needed but the server storage is not enough, in this case you must backup your data on the fly via the net, without the facility of storing locally and then transfer the data.There are many methods to backup your data on the fly, using rsync via ssh is one for example, but this post is about using netcat for a quick solution.Listening side, where the backup data will be stored, or destination:

~# mkdir /whatever_the_name_of_your_backup_dir~# cd !$~# netcat -l -p 12345 | pv | tar xjf -

Sending side, where the original data are, or source:

~# cd /~# tar cjf - --ignore-failed-read bin boot cdrom dev/ etc/ home/ initrd* lib/ root/ sbin/ usr/ var/ vmlinuz*  | pv | netcat -q 2 <YOUR_DESTINATION_IP> 12345

Don’t forget to create: /bin /media /mnt /opt /proc /selinux /srv /sys /tmpand chmod 1777 /tmp(This FHS is for a Debian Etch, please take care of different directories in your setup)

Categories
Uncategorized

Simple bash calculator

Put the following little snippet in your .bashrc/.bash_profile and you’ll have a handy little calculator:

? () { echo "$*" | bc -l; }

Use like this:

bash$ ? 2*24

Thanks textsnippets.com

Categories
Uncategorized

Column width in bash environment

export COLUMNS=150