Link to home
Start Free TrialLog in
Avatar of weihk
weihk

asked on

how to use if/then statements in crontab?

Hello,

I'm new to unix shell programming. I was wondering if there is a way to use if/then statements in crontab? If so, can you please give me an example, or the problem I'm working on is reading a file for a specific line (ex: hello there) and if it is read more than 2 times then execute a reboot of that particular server.

The code below is what I have so far but not sure how to fully utilize the if/then statement. Thanks for your help.
*/5 * * * * awk '{if($15 ~/XFMRDPAD/) shutdown -i6}' StructureService_PR.log

Open in new window

Avatar of gheist
gheist
Flag of Belgium image

You should not reboot UNIX automatically.

Specifying full path to commands helps in crontab.
No "if" statements in your command line, just gawk syntax.
ASKER CERTIFIED SOLUTION
Avatar of Todd Mummert
Todd Mummert

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of weihk
weihk

ASKER

i found out that i'm suppose to stop the IS (integration server) using this command:
call vtadmin stop server /StructureService_PR/initial/StructureService_IS

and reboot the project using this command:
call vtadmin start project /Projects/StructureService_PR/initial

can i just replace the "shutdown -i6" with those commands? or how will i be able to implement it into the code? thank you
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial