Bash

Dumb script for Picasaweb backup on Linux server & Amazon S3

Anurag Bhatia

Just wrote a quick script to pull dump of Picasaweb albums backup on my server & further to Amazon S3. Overall I have good trust on Google for data but it’s always a poor idea to leave all eggs in single bucket.

OK here’s the script (poorly written code. Literally spent 10mins on this, thus suggestions to improve my coding are more then welcome!)

 #!/bin/bash

Destination=<PUT YOUR DESTINATION HERE!>
google picasa list-albums | cut -d"," -f1 » $Destination/tmp/album_list.txt

cat $Destination/tmp/album_list.txt | while read album

do
          google picasa get “$album” $Destination/tmp
done

FileName=PicsBackup-`date ‘+%d-%B-%Y’`.tar
tar -cpzf $Destination/$FileName $Destination/tmp
gpg –output $Destination/$FileName.pgp -r –always-trust –encrypt $Destination/$FileName
s3cmd put $Destination/$FileName.pgp s3://YOUR-AWS-S3-BUCKET-ADDRESS-HERE

rm -r $Destination/tmp/*
rm $Destination/$FileName
rm $Destination/$FileName.pgp

	

Domain to IP/ASN/BGP block mapping script

Anurag Bhatia

Sleepless night. Reading more about Quagga and it’s options.

In meanwhile a quick 5min script to enable domain to BGP/IP/ASN mapping. This script is using basic dig command (for finding IP address) and Team Cymru whois service for IP to ASN/block mapping.

#!/bin/bash  
\# Script for domain name to IP/ASN/BGP block mapping  
hostname=v4.whois.cymru.com  
IP=$(dig $1 a +short)  
whois -h $hostname " -c -p $IP"

	

Simple bash script for IP-ASN mapping

Anurag Bhatia

Whenever I see a new unknown IP range, it gets hard to find exact source of that IP within command shell. Recently, I found a very interesting source of that information from Team Cymru. Here’s the resource.

I figured out (with a friend’s help) that using their whois server - v4.whois.cymru.com one can actually grab limited information as required. 


E.g

anurag@laptop:~$ whois -h v4.whois.cymru.com "  -v 8.8.8.8"
AS      | IP               | BGP Prefix          | CC | Registry | Allocated  | AS Name

15169   | 8.8.8.8          | 8.8.8.0/24          | US | arin     | 1992-12-01 | GOOGLE - Google Inc.

	

Quick simple script for automated database dumps

Anurag Bhatia

I tried looking for script for database dumps but most of them are way too complex then a simple solution one can implement. 

Thus, I wrote a quick simple 1 page (infact few lines) bash script for database dumps.

Here’s the code:  

#!/bin/bash

#Script for MySQL automated dumps

dbhost=DB-HOSTNAME-HERE  
dbusername=DB-USERNAME-HERE  
dbpassword=DB-PASSWORD-HERE

# Enter database names here  
dbname=( database1 database2 database3 )

for i in "${dbname[@]}"

do  
timestamp=backup_`date +%F.%T`  
output=$i+$timestamp  
mysqldump -h $dbhost -u $dbusername -p$dbpassword -C $i | bzip2 -c > /backups/MySQL-automated/$output  
done