On Sat, Mar 15, 2008 at 4:47 PM, Agnello George agnello.dsouza@gmail.com wrote:
i am trying to write a script on my *test machine *to check if the process are running , and if they are not need to start them any idea why this is not working ??
Try this:
#!/bin/sh -x
# In the line below, remove the space after = # Also, the file name is the 8th column, not 9th
SERVICES=`ls -la /etc/init.d/ |awk '{print $8 }' |sed -e 's/[^[:alnum:]]//g'`
for i in $SERVICES do
# It's not ps -aux, it's ps aux # Also, you might want to check for user # that is running the process as well.
if [ $(ps aux|grep -v grep |grep $i |wc -l) != 0 ]; then . /etc/init.d/$i start else echo " the service $i is running " fi done