PDA

View Full Version : How to use screen cmd in a cron script?



LouieLouie
7th June 2006, 03:39 AM
I've got a script that checks the status of a gameserver process via it's query port. This script works as a stand alone program. If the gameserver is down, the script creates a screen with the gameserver and parameters. BUT I can't get it to work from cron. I suspect that screen isn't being done right, and I thought I read somewhere that screen and cron don't play well. I was hoping to find some guidance....

Here's the cron command:

cd /path/scripts; ./game_cronmonitor.sh >> /path/scripts/cod2_cron.log

and the following is the contents of the game_cronmonitor.sh that is referenced in that cron cmd....

#!/bin/sh
# search for server status and restart if not running
if blah ip.address:port | grep -c DOWN;
then
sleep 10
if blah ip.address:port | grep -c DOWN;
then
cd /home/path/to/game/folder
screen -dmS gamename ./gamefile parameters
fi
fi

exit

tebbens
7th June 2006, 03:58 AM
If you run the script manually, does it work ?
Is /path/scripts/game_cronmonitor.sh executable ?

LouieLouie
7th June 2006, 04:13 AM
script works manually, yes.
it's executable, 755, and is owned by the same user as the cron user.

tebbens
7th June 2006, 04:26 AM
So the problem is your crontab.
Whats your output of: crontab -l

LouieLouie
7th June 2006, 05:09 AM
# 0,5,10,15,20,30,35,40,45,50,55 * * * * cd /path/scripts; ./gameserver_cronmonitor.sh >> /path/scripts/gameserver_cron.log #restarts non-responsive gameserver

tebbens
7th June 2006, 05:42 AM
man 5 crontab
Second paragraph.

LouieLouie
8th June 2006, 12:15 AM
read it, removed the comment line, still doesn't work.