Below is a script I've wrote to backup my routers and adsl modem, Any ideas to compact this script in less lines?
Each router have a different kind of structure as you can see.
#!/bin/sh
http_txt="10.0.0.59"
cgi="10.0.0.60"
http="10.0.0.66"
date="$(date +%d-%m-%y)"
dest="/home/yamash/"
archive_file="$dest$date.tgz"
local="$dest$date"
login="admin"
pass="PASSWORD"
mkdir $local
cd "$local"
echo "Iniciando Backup"
for http_txt_for in $http_txt; do
echo "$http_txt_for"
wget --auth-no-challenge --user=$login --password=$pass $http_txt_for/config.dat -O $http_txt_for.dat
done
for cgi_for in $cgi; do
echo "$cgi_for"
wget --user=$login --password=$pass $cgi_for/cgi-bin/export_settings.cgi -O $cgi_for.dat
done
for http_for in $http; do
echo "$http_for"
wget --user=$login --password=$pass $http_for/rom-0 -O $http_for
done
cd ..
tar czf $archive_file $local
#rm -R $archive_file $local
echo "Backup Finalizado"
Some possibilities:
echo
ing debug information.echo
s like this are like comments: They aren't code and they may get obsolete. Printing what's actually going on is much more useful for debugging.wget --output-document=/path/to/file
to avoidcd
ing beforewget
ting.tar -C ..
to go to the parent directory before doing thetar
operation withoutcd
.Why create a directory and a file name with the date? You only need a date indicator in the tarball name. The canonical solution for this sort of thing is to
and store the temporary files there. This also removes the need for the previous two tips.
$date
.