Dear salam to all
I want to excute the following script with help of cron scheduler every morning at 9.00 am. Can any body help me?
#!/bin/bash
LOG=/tmp/mylog.log
SECONDS=10
EMAIL=my@email.address
for i in $@; do
echo "$i-UP!" > $i.$LOG
done
while true; do
for i in $@; do
ping -c 1 $i &> /dev/null
if [ $? -ne 0 ]; then
STATUS=`cat $i.$LOG`
if [ $STATUS != "$i-DOWN!" ]; then
echo "`date`: ping failed, $i host is down!" |
mail -s "$i host is down!" $EMAIL
fi
echo "$i-DOWN!" > $i.$LOG
else
STATUS=`cat $i.$LOG`
if [ $STATUS != "$i-UP!" ]; then
echo "`date`: ping OK, $i host is up!" |
mail -s "$i host is up!" $EMAIL
fi
echo "$i-UP!" > $i.$LOG
fi
done
sleep $SECONDS
done
Regards,
SM Raza
Executing Bash Script by help of cron scheduler
Its simple.
run this command "crontab -e" then make an entry similar to given below
* 9 * * * /path/to/script
then save and exit. make sure the script has executable rights.
run this command "crontab -e" then make an entry similar to given below
* 9 * * * /path/to/script
then save and exit. make sure the script has executable rights.
Kind Regards
Mudasir Mirza (RHCE)
(+971)55-1045754
http://www.crystalnetworks.org
http://www.diglinux.com
Mudasir Mirza (RHCE)
(+971)55-1045754
http://www.crystalnetworks.org
http://www.diglinux.com
that will execute 60 times, once a minute from 9:00 to 9:59.
0 9 * * * is what you want.
it doesn't seem like the script will ever exit. perhaps cron is not the place for it.
0 9 * * * is what you want.
it doesn't seem like the script will ever exit. perhaps cron is not the place for it.
Watch out for the Manners Taliban!
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
remove the outer while loop so that it does exit after a 10 seconds.
install runit or daemontools (probably part of your distribution), and run it using that.
install runit or daemontools (probably part of your distribution), and run it using that.
Watch out for the Manners Taliban!
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
-
- Subedar
- Posts: 355
- Joined: Sat May 07, 2005 11:54 am
- Location: Lahore
- Contact:
AOA SM Raza
one suggestion:
what if mail delivered in case of only host down ?
and you can configure mail-to-sms from any service provider in pakistan so that you get mail at ur mobile as SMS.
one suggestion:
what if mail delivered in case of only host down ?
and you can configure mail-to-sms from any service provider in pakistan so that you get mail at ur mobile as SMS.
Regards
Rana Tanveer
+923224194457
Linux Student
For Affordable Web Development http://www.affordableprogrammers.com
http://www.qualityprogrammers.com
Rana Tanveer
+923224194457
Linux Student
For Affordable Web Development http://www.affordableprogrammers.com
http://www.qualityprogrammers.com