I have created a script that works as expected in shell but cron job does not seem to run it. when I check my cron mail, I see that it prints "hltv is not running" but does not create a screen session.
#!/bin/bash
if [[ $(netstat -a | grep '27027') == *27027* ]]; then
echo "tour 2 hltv is running"
else
echo "hltv is not running"
/usr/bin/screen -A -m -d -S tour2 ./start_hltv +connect xxx.xxx.xx.xx:27015 -port 27027 +exec hltv.cfg
fi
I have replaced my ip with xx.xxx.xx.xxx for privacy reasons.
Further details.. Well, I have a centos vps that I use for hltv (related to half life game) that runs on port 27027. Every once in a while, it crashes, so I was trying to create a script that would check if something is happening on that port and if not, it means process is crashed and need to start it.
I created script and named it "autorestart" and ran
chmod +x autorestart
This is the output i get from my cron job mail, but screen -ls does not show tour2 as valid screen.
Message-Id: <20140330021701.71D591A5B@hltvvps.localdomain> Date: Sat, 29 Mar 2014 22:17:01 -0400 (EDT)
hltv is not running
Thanks
Edit. Got this working.
#!/bin/bash
if [[ $(netstat -a | grep '27027') == *27027* ]]; then
echo "tour 2 hltv is running"
else
echo "hltv is not running"
cd /usr/hlds/tour2
chmod +x ./run_hltv (run_hltv has screen command)
sh run_hltv
autostartandstart_hltvin/etc/crontab?! o.O – Alexej Magura Mar 30 '14 at 14:50autorestartto run, every minute of every hour, every day of the month, every month, and every day of the week? Why don't you just have it run once, at like 1am, and then use something like cronwhip to make sure that it never gets missed? – Alexej Magura Mar 30 '14 at 14:51