Apr
30
2012

Linux’s bash shell script – Check running program

Since I have develop a script code to do automatic synchronize files between server and clients. The code is designed to run in background. To make sure that the program is still running the following code is used to recognize the running process.

#!/bin/sh
SERVICE=’httpd’
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
echo “$SERVICE service running, everything is fine”
else
echo “$SERVICE is not running” echo “$SERVICE is not running!” | mail -s “$SERVICE down” root
fi

This code can be modified by insert more functions to reach your purposes.


Comments are closed.




Member Area