the other day I wrote this script, it downloads the latest .torrent files from the ubuntu web site
each unsuccessful download hits the Ubuntu webpage page 2 times, so i only run it every 6 hours (via cron) on the scheduled Ubuntu release day, I avoid running it too often as I don't want to over load their server.
this is the mail.sh script called in the script above
I had a few scripts that email me their output, and i figured it was easier to make an email script and use that instead of rewriting it every time
still pretty new to scripting and programing in general, so any pointers on how to optimize these scripts will be appreciated.
each unsuccessful download hits the Ubuntu webpage page 2 times, so i only run it every 6 hours (via cron) on the scheduled Ubuntu release day, I avoid running it too often as I don't want to over load their server.
Code:
#!/bin/bash
##markp1989
##script to download torrents of the latest ubuntu release.
##setting the watch folder of your torrent client
watch=/home/rtorrent/watch
##setting where to log any downloads
log=/home/rtorrent/downloaded.ubuntuget
##cding to the watch folder
cd $watch
##scraping part of the releases page to find out the name of the latest version
newest=$(curl http://releases.ubuntu.com/ | grep ")</a>" | cut -f2 -d'"' | cut -f1 -d'/' | tail -n 1)
##setting the base url which is http://releases.ubuntu.com/NameOfNewestRelease
baseurl="http://releases.ubuntu.com/$newest/"
#running a loop for every torrent link on the latest release page
for i in $(curl $baseurl | grep iso.torrent | cut -f10 -d'"' ); do
##checking weather the torrent file already exists, downloading only if the file doesnt exist
if [ -f $i ];
then
#outputing that the file exists
echo "file $i already exists"
else
##downloading the torrentfile
wget $baseurl$i
##logging the download
echo $i >> $log
fi
done
##if a download log exists (will only exist if atleast one .torrent file was downloaded)
##then I get an email with the content of the log file sent to me , after that that log file is deleted.
if [ -f $log];
then
mail.sh "[email protected]" "ubuntuget output $(date)" " $(cat $log)"
rm $log
fi
this is the mail.sh script called in the script above
I had a few scripts that email me their output, and i figured it was easier to make an email script and use that instead of rewriting it every time
Code:
#!/bin/bash
##markp1989
##small email script
##usage
##mail.sh "recipent" "subject" "body"
## eg mail.sh "[email protected],[email protected]" "Just saying hi" "hey, just emailing you to give you this notification"
recipent=$1
subject=$2
body=$3
echo -e "$(date) \n\n $body" | mail -s "$subject" $recipent
still pretty new to scripting and programing in general, so any pointers on how to optimize these scripts will be appreciated.