bash script to check if a program is running

I'm a bit new to bash programming and I was assigned the job of writing a script that will check to see if a program server is running and to restart the program if it is not up. The script is supposed to check the program every hour (which I have looked up and I believe I know how to do) and send emails when it goes down. Can anyone help me get start with this script? I really have no idea where to begin...

check out the man pages for pgrep, ps,mail/mailx

hi mcknz, here is a simple script. this will check if oracle database is running.

db_stat=`ps -ef|grep ${ORACLE_SID}|grep pmon|wc -l`
if [[ $db_stat = 1 ]] ;
then
echo "running"
else
echo "not running"
fi

one technique is by using grep and wc -l to count the line number. hope this helps.

1 Like

turns out i don't need the part about sending an email, but i'm still unsure about the whole restarting process. my code right now is

 #!/user/bin/perl
state=`ps -p #####|grep "server_name" -c`
if [[ $state != 1]] ;
then
 
fi 

i'm not sure what to write for the then statement. my supervisor told me to use a path to a file in a directory, but im not sure how to implement that. anyone got any ideas?