PDA

View Full Version : Script to archive all bash scripts from a folder and email it away as an backup



Fli
11-14-2014, 05:28 PM
Script to archive all bash scripts from a folder and email it away as an backup
This script also encode archive, so it needs decoding


echo "
Backup all script files from /root with higher than 677 permission and mail them out as backup

MUTT must be installed!! Now listing mutt installed packages:"
which mutt

echo "If mutt dir not listed, then u need: yum install mutt before running this script. Hit any key to continue"
#read dfsdfds

[email protected]

# find files and pack it
find /root/* -prune -type f -perm 700 -exec tar rvf rootscripts$(hostname).tar {} \;
gzip rootscripts$(hostname).tar
ls -lh | grep rootscripts
cat rootscripts$(hostname).tar.gz | base64 > rootscripts$(hostname).tar.gz_base64

# mail it
file=rootscripts$(hostname).tar.gz_base64
echo "$(hostname) root scripts backup" | mutt -a $file -s "Root scripts $(hostname)" -- $maill

# remove arcive after mailing
echo "Removing backup file after mailing. Done"
rm -rf rootscripts$(hostname).tar.gz*

to setup cronjob,
ln -s /path/to/script /etc/cron.weekly/script