Printable Version of Topic

Click here to view this topic in its original format

Linuxhelp _ Programming in Linux _ My first cron script

Posted by: {XN}Boylett Aug 28 2006, 05:28 AM

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

Posted by: michaelk Aug 28 2006, 06:21 AM

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.

Posted by: {XN}Boylett Aug 28 2006, 06:42 AM

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 * * * * *

Posted by: {XN}Boylett Aug 28 2006, 07:33 AM

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


Gets me an error message

Posted by: michaelk Aug 28 2006, 09:44 AM

What is the error message?

Posted by: {XN}Boylett Aug 28 2006, 11:41 AM

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.

Posted by: michaelk Aug 28 2006, 12:11 PM

*/2 * * * * /server/sv_up.sh >/dev/null 2>&1

Is this line 4?

Posted by: {XN}Boylett Aug 29 2006, 07:04 AM

QUOTE (michaelk @ Aug 28 2006, 06:11 PM) *
*/2 * * * * /server/sv_up.sh >/dev/null 2>&1

Is this line 4?

Yes

Posted by: michaelk Aug 29 2006, 10:17 AM

I do not see anything obvoiusly wrong with the line.

Posted by: {XN}Boylett Aug 29 2006, 03:31 PM

Would it help if i said i get the error about 2 minutes after starting cron and in the cron.log ?

Posted by: michaelk Aug 29 2006, 04:53 PM

Try changing the line to
* * * * * /server/sv_up.sh >/dev/null 2>&1

This will run the script every minute.

Posted by: {XN}Boylett Aug 30 2006, 02:15 PM

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

Posted by: michaelk Aug 30 2006, 04:34 PM

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.

Posted by: {XN}Boylett Sep 11 2006, 01:55 PM

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?

Posted by: michaelk Sep 11 2006, 03:36 PM

Does the script work running from a console?

Posted by: {XN}Boylett Sep 13 2006, 11:32 AM

Sorry, what does that mean? I run Cron on my computer. The Crontab and sv_up.sh are both in the same file

Posted by: michaelk Sep 13 2006, 03:40 PM

cron at the scheduled time executes the script sv_up.sh. You should be able to execute this same script manually from terminal window.

Posted by: {XN}Boylett Sep 13 2006, 05:26 PM

Whats a terminal window?

Posted by: michaelk Sep 13 2006, 05:36 PM

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.

Posted by: {XN}Boylett Sep 14 2006, 10:59 AM

i have windows xp. how do i start it?

Posted by: DS2K3 Sep 14 2006, 01:37 PM

You have CRON on Windows XP?

Posted by: {XN}Boylett Sep 14 2006, 02:24 PM

I did. Now Ive just installed windows server 2003 and i found the terminal thing biggrin.gif

Posted by: michaelk Sep 14 2006, 03:58 PM

I'm totaly lost now.....

Posted by: {XN}Boylett Sep 15 2006, 03:11 PM

mellow.gif um ok ill have a fiddle with it. ill post the ^new^ code if it doesnt work.

Posted by: DS2K3 Sep 15 2006, 05:00 PM

Sorry - Should you not be on a Windows help site?

Posted by: {XN}Boylett Sep 16 2006, 03:01 AM

with a cron and a shell script?

Posted by: michaelk Sep 17 2006, 09:32 AM

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.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)