Help - Search - Members - Calendar
Full Version: Need Cron Job To Do: If File !exists Then Run App
Linuxhelp > Support > Technical Support
failrate
Man, my bash skills are rusty.

Basically, I'm trying to run a frequent cron job to test for the existence of a lockfile. If the lockfile is where it's supposed to be, then cron just goes back to sleep.

If the lockfile is missing, then cron is supposed to run an application (rebooting a Zope server). It seems simple, but I'm not much of a sysadmin.

Thanks to anyone who can suggest a solution.
hughesjr
how about this:

CODE
#!/bin/bash

if [ ! -f /path/to/file ] then
 /file/to/run
fi


where /path/to/file is the lock file and /file/to/run is the file (or command) to start the server ... save the file as a script, and make it execuable ... then call the script from cron. If the lock file doesn't exist it should run the command /file/to/run
failrate
Wow, yeah, that's exactly what I need, and a lot simpler than I thought it would be. I really appreciate the help.
failrate
#!/bin/bash

if [ ! -f /path/to/file ];
then /file/to/run;
fi

Don't forget the semicolons wink.gif
Hemant
I guess semicolon is not required!!!
hughesjr
If you want to put the then, on the top line (like I did) you need the first semicolon (but the second one shouldn't be required) ... so for bash scripts this:
QUOTE
if [ condition1 ]
then
  command1
  command2
  command3
elif [ condition2 ]
# Same as else if
then
  command4
  command5
else
  default-command
fi


is the same as this:
QUOTE
if [ condition1 ]; then
  command1
  command2
  command3
elif [ condition2 ]; then
# Same as else if
  command4
  command5
else
  default-command
fi


using a semicolon in a bash script line is executing an enter command.
failrate
Either way, it totally worked. My server is now very mellow. Thanks again.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2017 Invision Power Services, Inc.