I am running a Bash Script via Cron Job on my server and i need to invoke and end it self.
Script :
#!/bin/bash
while [ true ]
do
DATE=`date "+%d.%m.%Y. %H:%M"`
MSG='STUFF HERE'
test=`/usr/sbin/asterisk -rx "sip show peers" | grep UNKNOWN `
if [ -z "$test" ]; then
sleep 100
else
top=`top -bn1 | tail`
echo -e "$test" | mail -r "support@abc.com" -s "SIP Peer UNKNOWN/UNSPECIFIED `hostname` $DATE" abc@cabc.com
sleep 900
fi
done
I need it to not reset on its own i will call the script thru cron when ever I want.
Thanks
Advertisement
Answer
When you call it with cron, cron must take care of the looping.
Remove the while and sleep. You want to sleep longer when a warning has been mailed, this should be managed outside your detection code. Later on you will be monitoring a lot more, sending mails to different persons only during working hours, and perhaps using other things than mail as well.