Help - Search - Members - Calendar
Full Version: My first cron script
Linuxhelp > Support > Programming in Linux
{XN}Boylett
In the crontab:

CODE
# Restart server
0,2 * * * * /server/sv_up.sh >/dev/null 2>&1



In sv_up.sh:

CODE
#!/bin/sh

mtaserverdir="/server/"
process=`ps auxw | grep linuxq3ded | grep -v grep | awk '{print $11}'`

if [ -z "$process" ]; then

  echo "Couldn't find MTA Server running, restarting it."
  cd "$mtaserverdir"
  nohup ./mtaserver +exec ffa.cfg &
  echo ""

fi


What im trying to do is make sv_up.sh run every 2 minutes.
And what I want sv_up.sh to do is start mtaserver.exe if it isnt running
Can anyone help me? It doesnt work dry.gif
michaelk
Does the script run successfully from the console?
0,2 * * ... means runs on 0 and 2 minutes or every hour not every 2 minutes. */2 means every two minutes.
{XN}Boylett
QUOTE (michaelk @ Aug 28 2006, 12:21 PM) *
Does the script run successfully from the console?
0,2 * * ... means runs on 0 and 2 minutes or every hour not every 2 minutes. */2 means every two minutes.


does that mean */2 * * * * *
{XN}Boylett
CODE
# Restart server
*/2 * * * * /server/sv_up.sh >/dev/null 2>&1


Gets me an error message
michaelk
What is the error message?
{XN}Boylett
QUOTE (michaelk @ Aug 28 2006, 03:44 PM) *
What is the error message?


CODE
28.08.2006 13:28 Cron started.
28.08.2006 13:29 Error in crontab, line 4: improper value.
michaelk
*/2 * * * * /server/sv_up.sh >/dev/null 2>&1

Is this line 4?
{XN}Boylett
QUOTE (michaelk @ Aug 28 2006, 06:11 PM) *
*/2 * * * * /server/sv_up.sh >/dev/null 2>&1

Is this line 4?

Yes
michaelk
I do not see anything obvoiusly wrong with the line.
{XN}Boylett
Would it help if i said i get the error about 2 minutes after starting cron and in the cron.log ?
michaelk
Try changing the line to
* * * * * /server/sv_up.sh >/dev/null 2>&1

This will run the script every minute.
{XN}Boylett
QUOTE (michaelk @ Aug 29 2006, 10:53 PM) *
Try changing the line to
* * * * * /server/sv_up.sh >/dev/null 2>&1

This will run the script every minute.


thats works fine. also how do u turn cron off once started it? lol tongue.gif
michaelk
All I can say is interesting. I'm not sure what is going on here at the moment. You can turn of cron but that will stop all other jobs too.
{XN}Boylett
oh well im happy it doing that every minute. anyway, about this shell script...
CODE
#!/bin/sh

mtasadir="/server_windows"
process=`ps auxw | grep linuxq3ded | grep -v grep | awk '{print $11}'`

if [ -z "$process" ]; then

  echo "Couldn't find MTA running, restarting it."
  cd "$mtasadir"
  nohup ./mtaserver +exec ffa.cfg &
  echo ""

fi

This code should start a program called mtaserver.exe, but it doesnt. cron runs it and it opens, but the server doesnt start. can anyone fix it?
michaelk
Does the script work running from a console?
{XN}Boylett
Sorry, what does that mean? I run Cron on my computer. The Crontab and sv_up.sh are both in the same file
michaelk
cron at the scheduled time executes the script sv_up.sh. You should be able to execute this same script manually from terminal window.
{XN}Boylett
Whats a terminal window?
michaelk
A console or terminal window is an application typically called xterm. It is similar to the windows DOS prompt box i.e c:\. So you would type in the command
/server/sv_up.sh

On the desktop toobar there is an icon that looks like a video monitor. This should start xterm.
{XN}Boylett
i have windows xp. how do i start it?
DS2K3
You have CRON on Windows XP?
{XN}Boylett
I did. Now Ive just installed windows server 2003 and i found the terminal thing biggrin.gif
michaelk
I'm totaly lost now.....
{XN}Boylett
mellow.gif um ok ill have a fiddle with it. ill post the ^new^ code if it doesnt work.
DS2K3
Sorry - Should you not be on a Windows help site?
{XN}Boylett
with a cron and a shell script?
michaelk
The console or terminal window has nothing to do with windows or windows terminal server.
Like I described before it is an application that lets you type and run commands like DOS or windows cmd window.

BTW what distribution / version of linux are you running.
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.