CardSharing-X

» CardSharing Section => General Sharing Discussion => » CS Help and Tutorials « => Newcs Help => Topic started by: golub on March 07, 2012, 10:28:47 PM

Title: newcs check and restart if neede with cron?
Post by: golub on March 07, 2012, 10:28:47 PM
Hi, I have problems with newcs, and I need a check and restart script for newcs via cron. This script need to check newcs every 5 minuts and if it down, to restart it.

I try to do it with this script:

#!/bin/bash
if ps -ef | grep newcs | grep -v grep ; then
echo && date>> /var/log/newcs.ok
else
/usr/local/bin/newcs &
echo && date>> /var/log/newcs.restart

fi


I named this script newcscheck.sh and gave atributes 755

and I add a cronjob:
*/1 * * * * /var/script/newcscheck.sh

What's wrong?

Thanks in advance
Title: newcs check and restart if neede with cron?
Post by: labud on March 08, 2012, 02:29:58 AM
C/P



#!/bin/sh

if ps x |grep -v grep |grep -c newcs >/dev/null
then
echo "newcs... ok"
else
date=`date`
echo "Restarting newcs : $date" >> /tmp/lognewcs.txt

echo "newcs... restarting"
/usr/bin/newcs -b >>/tmp/lognewcs.txt &
fi
Title: newcs check and restart if neede with cron?
Post by: labud on March 08, 2012, 02:32:08 AM
C/P




The script i use is witn name/location /etc/chkncs :

#!/bin/bash
if ps -ef | grep newcs | grep -v grep ; then
#The process is running, bring it to the front
echo "Newcs is running"
echo && date >> /var/log/newcs.ok
exit 0
fi
#The process is not running, start it
echo "Newcs startes"
echo && date >> /var/log/newcs.check
newcs


And in "crontab -e"
Run evry 5 min.

# m h dom mon dow command
*/5 * * * * /etc/chkncs
Title: newcs check and restart if neede with cron?
Post by: labud on March 08, 2012, 02:34:05 AM
(http://img37.imageshack.us/img37/3730/newcs.jpg)




this is the image with this command, how to make the script, and how to add this script to running periodicaly with crontab ?
Title: newcs check and restart if neede with cron?
Post by: golub on March 09, 2012, 08:37:22 PM
Thanks, script work like charm

Good work