Linux Help
guides forums blogs
Home Desktops Distributions ISO Images Logos Newbies Reviews Software Support & Resources Linuxhelp Wiki

Welcome Guest ( Log In | Register )



Advanced DNS Management
New ZoneEdit. New Managment.

FREE DNS Is Back

Sign Up Now
 
Reply to this topicStart new topic
> Need Cron Job To Do: If File !exists Then Run App
failrate
post Oct 17 2004, 04:04 PM
Post #1


Whats this Lie-nix Thing?
*

Group: Members
Posts: 4
Joined: 17-October 04
Member No.: 3,977



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.
Go to the top of the page
 
+Quote Post
hughesjr
post Oct 17 2004, 06:26 PM
Post #2


Its GNU/Linuxhelp.net
*******

Group: Admin
Posts: 3,433
Joined: 25-July 03
From: Corpus Chrsiti, TX, USA
Member No.: 1,151



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


--------------------
Johnny Hughes
hughesjr@linuxhelp.net
Enterprise Alternatives: CentOS, WhiteBoxEL
Favorite Workstation Distros (in order): CentOS, Gentoo, Debian Sarge, Ubuntu, Mandrake, FedoraCore, Slackware, SUSE
Favorite Server Distros (in order): CentOS, WhiteBoxEL, Debian Sarge, Slackware, Mandrake, FedoraCore, Gentoo, SUSE
Go to the top of the page
 
+Quote Post
failrate
post Oct 17 2004, 09:13 PM
Post #3


Whats this Lie-nix Thing?
*

Group: Members
Posts: 4
Joined: 17-October 04
Member No.: 3,977



Wow, yeah, that's exactly what I need, and a lot simpler than I thought it would be. I really appreciate the help.
Go to the top of the page
 
+Quote Post
failrate
post Oct 17 2004, 10:50 PM
Post #4


Whats this Lie-nix Thing?
*

Group: Members
Posts: 4
Joined: 17-October 04
Member No.: 3,977



#!/bin/bash

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

Don't forget the semicolons wink.gif
Go to the top of the page
 
+Quote Post
Hemant
post Oct 17 2004, 11:16 PM
Post #5


RMS is my Hero
******

Group: Support Specialist
Posts: 782
Joined: 6-October 02
From: Trichy,INDIA
Member No.: 29



I guess semicolon is not required!!!


--------------------
Hemant Kumar
user posted image
hemant@linuxhelp.net
Go to the top of the page
 
+Quote Post
hughesjr
post Oct 18 2004, 05:24 AM
Post #6


Its GNU/Linuxhelp.net
*******

Group: Admin
Posts: 3,433
Joined: 25-July 03
From: Corpus Chrsiti, TX, USA
Member No.: 1,151



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.


--------------------
Johnny Hughes
hughesjr@linuxhelp.net
Enterprise Alternatives: CentOS, WhiteBoxEL
Favorite Workstation Distros (in order): CentOS, Gentoo, Debian Sarge, Ubuntu, Mandrake, FedoraCore, Slackware, SUSE
Favorite Server Distros (in order): CentOS, WhiteBoxEL, Debian Sarge, Slackware, Mandrake, FedoraCore, Gentoo, SUSE
Go to the top of the page
 
+Quote Post
failrate
post Oct 19 2004, 12:12 AM
Post #7


Whats this Lie-nix Thing?
*

Group: Members
Posts: 4
Joined: 17-October 04
Member No.: 3,977



Either way, it totally worked. My server is now very mellow. Thanks again.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 21st October 2017 - 05:35 AM