Inside crontab -e , i have added this entry
* * * * * /usr/bin/memcached_autostart.sh
And inside /usr/bin i have the script named memcached_autostart.sh
/usr/bin memcached_autostart.sh
#!/bin/bash
ps -eaf | grep 11211 | grep memcached
# if not found - equals to 1, start it
if [ $? -eq 1 ]
then
memcached -d -m 16 -p 11211 -u nobody
else
echo "eq 0 - memcache running - do nothing"
fi
When i tested this manually this way
Started the Memcache
memcached -d -m 16 -p 11211 -u nobody
ps -eaf | grep 11211 | grep memcached
nobody 611 1 0 13:28 ? 00:00:00 memcached -d -m 16 -p 11211 -u nobody
Then killed the process
kill -9 611
I was expecting that the crontab automatically starts the Memcache if its down , but it is not starting the Memcache , please tell me if i am doing anything wrong .
See if your crontab is working
After test it, The shell exit can be greater than 1, so try to change for this: