1834771 Members
3361 Online
110070 Solutions
New Discussion

Re: Cron Job Needed

 
Hunki
Super Advisor

Cron Job Needed

We have a requirement to bounce one application every Sunday and then check whether it came back fine or not after bouncing, along with that we need to avoid bouncing it if its in maintanance.

I have to make this cron job where if one of the proccess ( called PROV ) is less than 1 , then its probably down for maintanance and I need to send the page to team telling abt it.

Secondly, if the process is equal to 49, then i need to restart the application.

Thirdly , once I bounce the application( as in step 2) then it shud check whether the number of processes is equal to 49 and if not then notify the team.

I have the sample script in the attachment.
I need one single script to do all this.
7 REPLIES 7
Kent Ostby
Honored Contributor

Re: Cron Job Needed

To add this to cron, you would need to do a few things.

1) Use full paths for the script.
You need to make sure that any environment variables that are needed are added to the script. You need to make sure that you use full paths for all the commands in the script.

2) In crontab, you would add a line that would say:

30 12 * * 0 /mypath/myscript

"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
Hunki
Super Advisor

Re: Cron Job Needed

Apart from that is the script gud to go as far as the logic goes.I want to club everything into a single script and I am not getting any downtime to test it out myself.

Thanks
Volker Borowski
Honored Contributor

Re: Cron Job Needed

Hello,

no, I see two problems:

1) you need to recalculate $prov after the restart, otherwise it will still contain the value from the very beginning (most likely 49, if the script decided for a bounce)

2) if anyone has a "vi" to file with one of the "grep" target-words (like "vi PROVIDENCE"), you will misscalculate. Is there a way using an application tool to query the application "are you up and ok ?".

Hope this helps
Volker
Hunki
Super Advisor

Re: Cron Job Needed

I made the script but whats wrong with the function in the script:

. /appl/s/test/cur/admin/tux/.profile
prov=`ps -ef|grep -v grep |grep PROV |grep sld|grep -v PROVUPD|grep -v PROVFTTP|wc -l`

if [ $prov -lt 1 ]
then
mailx -s "Prov is down so I am not retstarting it" vg@tt.com < /tmp/1.txt
exit
fi

if [ $prov -eq 27 -o $prov -gt 1 ]
then
/appl/tux/bin/tmshutdown -w 30 -s PROV 2>&1 > /tmp/provbounce.log
/appl/tux/bin/tmshutdown -w 30 -s PROVMGR 2>&1 >> /tmp/provbounce.log
/appl/tux/bin/tmboot -s PROVMGR 2>&1 >> /tmp/provbounce.log
/appl/tux/bin/tmboot -s PROV 2>&1 >> /tmp/provbounce.log
check_prov
fi

check_prov()
{
prov_new=`ps -ef|grep -v grep |grep PROV |grep sld|grep -v PROVUPD|grep -v PROVFTTP|wc -l`
if [ $prov_new -lt 27 -a $prov_new -gt 1 ]
then
mailx -s "Not all PROV processes started after bounce" vg@tt.com < /tmp/provbounce.log
fi
}
Hunki
Super Advisor

Re: Cron Job Needed

Error i get is :
check_prov: not found
Mark Ellzey
Valued Contributor

Re: Cron Job Needed

Hi,

If you are going to use functions in a script, you have to define them before you call them. Move your function definition to the top of the script, and you should be ok.

Regards,
Mark
Hunki
Super Advisor

Re: Cron Job Needed

I found this out jus before your reply.But this worked,Thanks to all of you for replying back, appreciate, This forum rocks!!!