System Administrators’s ‘common tasks’ are usually monitoring numbers of servers and network connections, and doing each monitoring is rather tedious. So to make our jobs and lives easier, we write scripts to automate repetitive tasks.
Since this is my Linux blog anyway, I decided to share one of scripts that I use in the office. This one is the Perl script that I use to check a specific site if the keyword is present, hence confirming that the site is up and accessible.
In this example I am using dattebayo.com’s parsing URL to test the script.
Dattebayo is one of the subtitling groups that provide fansubs of famous Japanese animes like Naruto and Bleach.
This script requires that you have the following packages installed:
- perl
- mutt
- sendmail or equivalent MTU
Please refrain from parsing the URL too many times or DB will ban your IP. Read their terms of usage here.
#!/usr/bin/perl -w
$get_url=”GET http://dattebayo.com/t/dump”;
$sidebar_list=`$get_url`;
$keyword=”Bleach”;
$date=`date +%c`;
#print $sidebar_list;
if ( $sidebar_list =~ /$keyword/ ) {
# print “Site is UP”;
# print $sidebar_list;
}
else {
`echo “Cannot Open Site. Check Server. \nTime Stamp: $date ” > text_mesg.txt`;
`cat text_mesg.txt|mutt -s “DB Site Error” “kamotegirl\@pinoytux.com”`;
}
Then put this in your crontab set to run every 2 hours so as not to flood the webserver with spurious requests (see above warning).
# crontab -e
Enter this line:
* */2 * * * /home/bom/shippuuden.pl (Change this to where you saved your script)
Save and exit.
Your shippuuden script is now set to run and send email to your address if the site is inaccessible.
Do you find this script useful or trash?
Popularity: 17% [?]



















Leave a comment