cron's irregular responds


 
Thread Tools Search this Thread
Operating Systems Linux Red Hat cron's irregular responds
# 1  
Old 05-19-2011
cron's irregular responds

hi,
i ve constructed a script to monitor the crond ,if the crond service is not available/not running then a mail ll be sent the mention mail id.. here the code

Code:
crond=`service crond status|grep pid |awk '{print $5}'|cut -c1-7`
if [ "$crond" != "running" ];
   then
   echo -e "the CRON jOb is currently offline" | mail -s " ******CRONTAB ALERT*******" srini@yyyyyyyyy.com
fi

then i ve given the entry for cron as
Code:
* * * * * /usr/local/myscripts/cronstatus.sh

Now the issue is though the crond is running me getting the alert each minute. Where im going wrong Smilie

Moderator's Comments:
Mod Comment Please use [code] and [/code] tags when posting code, data or logs etc. to preserve formatting and enhance readability. Also please refrain from overly use of font formatting, thanks.

Last edited by zaxxon; 05-19-2011 at 09:44 AM.. Reason: code tags, fonts etc.
# 2  
Old 05-19-2011
Add set -x at the beginning of your script.
Use following line in crontab:
Code:
* * * * * /usr/local/myscripts/cronstatus.sh >> /tmp/mycron.log 2>&1

My guess is, that there will not be "running" in that $crond, since you don't have PATHs etc. available when starting scripts via cron. You have no environment active so commands like service, cut, awk, grep... will not be found and so with produce some errors where the test fails.
After a run there should be a log file /tmp/mycron.log where the output can be analyzed.
# 3  
Old 05-19-2011
Excuse me if, but are you trying to monitor cron by using cron? If crond isn't running, neither will your script, and you won't get any notification anyways.
# 4  
Old 05-19-2011
Oh lol good point Smilie Time to go home heh Smilie
# 5  
Old 05-20-2011
cron's irregular responds

hi zaxxon,thanks for ur comments and then U r rite , i got some error in the logs as
Code:
+++ service crond status
/usr/local/myscripts/cronstatus.sh: line 3: service: command not found
+++ awk '{print $5}'
+++ cut -c1-7
++ crond=
++ '[' '' == running ']'

now what can i do , now to get the environment .. Myself newbie to the scripting provide some solutions..

---------- Post updated 05-20-11 at 12:57 AM ---------- Previous update was 05-19-11 at 11:35 PM ----------

Quote:
Originally Posted by pludi
Excuse me if, but are you trying to monitor cron by using cron? If crond isn't running, neither will your script, and you won't get any notification anyways.
fine pludi .. valuable point , let assume the same code for httpd service now whats your solution??????Smilie may i know that?
# 6  
Old 05-20-2011
For httpd it would work, as long as cron is running. The path issue aside your script already does what it should do, you only have to hard-code the complete path to the service command (which service). But it's just not possible to monitor if a program is running from within that program. Think about it this way: if you are alive, you can tell if someone else is alive, and you know that you yourself are alive. But if you're dead, you have no way of telling that to anyone.
# 7  
Old 05-20-2011
MySQL

Quote:
Originally Posted by pludi
For httpd it would work, as long as cron is running. The path issue aside your script already does what it should do, you only have to hard-code the complete path to the service command (which service). But it's just not possible to monitor if a program is running from within that program. Think about it this way: if you are alive, you can tell if someone else is alive, and you know that you yourself are alive. But if you're dead, you have no way of telling that to anyone.
ok ok got ur point ... could u suggest me some other script to monitor the httpd service and send me alert when the service is offline...
Login or Register to Ask a Question

Previous Thread | Next Thread

1 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to convert irregular lines into formatted column using awk in windows2003 server environment?

Dear experts, I'm newbie to awk scripting. Need your great help to convert the irregular lines into column using awk in windows2003 server environment. (Sorting based on "Pri Number" column) Input files is as follows: Partition Name: OA Partition UID: ... (0 Replies)
Discussion started by: ruirus
0 Replies
Login or Register to Ask a Question