-
cpid.sh (simple script to do check for any process):
Code:
#!/bin/sh
if [ ! "$1" ]; then
echo "Usage: cpid <process>"
exit 2
fi
a=`ps -ef | grep -i $1 | grep -v grep | grep -v cpid`
if [ $? = 0 ]; then
exit 0
else
exit 1
fi
Add entry to your cronjob:
0,20,40 * * * * `<pathtocpid>/cpid <process>`; if [ $? = 0]; then <dowhateverprocessrunning>; else <dowhateverprocessnotrunning>; fi
Ie,
Code:
0,20,40 * * * * `/bin/cpid syslogd`; if [$? = 0]; then echo "Process is running"; else echo "Process is not running"; fi
Note, you will probably not want to echo from cron but do something else, maybe pipe it to sendmail or something or maybe restart it...
/nebulus
-
Well, thanks a bunch guys. I managed to do it ( get the script working I mean ). The method I used was simpler than ( IMHO ) the ones suggested by neb and Bart.
Code:
if
/usr/xpg4/bin/grep -i -q xxxx pm.txt
then
echo "The process xxxx is: Up and Running!"
else
echo "The process xxxx is: Not Running!"
fi
echo
Basically, pm.txt is the output of the ps -ef |grep -i xxxx command (its a required file, so I thought I'd use it. I couldve gone the other way and searched the actual ps output on screen, but since the file is there... and is updated each time, why not use it, right?). Searching through the file, I find the desired string xxxx. I've specified -q which hides the output, yet returns the status of the command to be successful. It can only be used with the /usr/xpg4/bin/grep version of grep, mind you.
The remaining echos are self-explainatory. :rolleyes:
heh, crappy, I know.. but it works. :) yay!
Now for the cron jobs!
-
would this be considerd a script?
i put this in a file called general-install
./configure
make
make install
somethimes i hate having to stick around for a file to install cause they can take a while so il copy this to the directory and cd there then type ./general-install and im set
-
You may want to start a new thread, but yes, it's a script.
Now instead of a script, what about :
./configure && make && make install
"make" will be executed only if "./configure" returns zero (true), and "make install" will be executed only if "make" returns zero. Then you don't have to wait for each command to complete to type in the next command.
If "./configure" completes successfully, and "make" fails, you can do the necessary changes and type:
make && make install
Peace always,
<jdenny>