Monthly Archive for May, 2009

Send each directory over ssh to their own gzipped tar file (.tar.gz)

Find directories in the directory you are standing in:
-maxdepth 1 -type d

Exclude the first ‘.’ :
-mindepth 1

Remove the ./ part from the list:
sed s@^.\/@@gi

Tar-gzip the directory with compression 1 for faster network transfer:
tar -cv $a | gzip -1

Send the file to the dd program:
ssh -l user server "dd of=/path/to/$a.tar.gz"

Wrapping it into a small example script:

for a in `find . -mindepth 1 -maxdepth 1 -type d | sed s@^.\/@@gi`; do 
(tar cv $a | gzip -1) | ssh -l user server "dd of=/path/to/$a.tar.gz" ;
done

I suggest you install a ssh-key before doing this, or you will have to type the user password for each directory. This script does not support spaces in directory names.

The script below handle directories with space in them, just like “Document and Settings”.
I print each file (%p) with a colon at the end. The seperator used by the for-loop is also the colon which is defined by the IFS variable.

IFS=":"
for a in `find . -mindepth 1 -maxdepth 1 -type d -printf '%p:' | sed s@^\".\/@\"@gi`; do
(tar cv $a | gzip -1) | ssh -l username servername "dd of='/outputdir/$a.tar.gz'" ;
done
unset IFS

Boot the ubuntu-live cd, making the network start.
livecd$ ssh-agent
livecd$ ssh -l username server -A
server$ ssh-add

root@ubuntu:/media# dd if=/dev/sda2 | ssh -l username hostname "dd of=/path/to/save/my_backup_sda2.ntfs.disk"
The authenticity of host 'hostname (192.168.1.1)' can't be established.
RSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'hostname,192.168.1.1' (RSA) to the list of known hosts.
username@hostname's password:
38957625+0 records in
38957625+0 records out
19946304000 bytes (20 GB) copied, 2541 s, 7,8 MB/s
37811184+2292882 records in
38957625+0 records out
19946304000 bytes (20 GB) copied, 2532.89 s, 7.9 MB/s
root@ubuntu:/media#

Scripted download of AVG definitions with BASH


Here is a oneliner of how to download avg definitions. For the full version updates, just change free.avg.com to www.avg.com on the oneliner.

wget -q -O - http://free.avg.com/download-update | grep "http://[^\"]*\.bin" -o | xargs wget

Here is a small script to download updates:

cd /path_for_updates/avg/free
for a in `wget -q -O - http://free.avg.com/download-update | grep "http://[^\"]*\.bin" -o`
do
        f=`basename $a`
        test -r $f || wget $a
done
cd /path_for_updates/avg/full
for a in `wget -q -O - http://www.avg.com/download-update | grep "http://[^\"]*\.bin" -o`
do
        f=`basename $a`
        test -r $f || wget $a
done

Here is a improved downloader for AVG:

cd /downloadpath/
for a in `(wget -q -O - "http://www.avg.com/download?prd=ibw"; wget -q -O - "http://www.avg.com/download?prd=afe"; wget -q -O - "http://free.avg.com/download?prd=afe"; wget -q -O - "http://www.avg.com/download?prd=ibw") | egrep "http://[^\"]*\.(bin|exe|sh|deb|gz|rpm|rar|iso|zip)" -o| sort | uniq`
do
        echo $a
        f=`basename $a`
        test -r $f || wget $a
done