Discussion Locked

unix shell script

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

hello,
i am trying to come up with a simple shell script that will check for a particular process name and if the process is not running start the process by defining the start process command.....

any help would be greatly appreciated....

thanks,
bill

7 replies

by kevin anderson

this won't always work, but

ps aux|grep XXXX

where xxxx is the process name will find the process.

generally, you start a process by calling it.

When in doubt, use

xxxx restart

most prebuilt scripts will stop the service, and then restart it. If it isn't running, you'll get an error indicating that it isn't running, but that won't matter. The process will still start in the second half.

Not sure that's a complete answer, but it's a start...

Kev.

by papril

This little one should do it... Don't forget to change the variables with what you want before running it.

--- snip ---

#!/bin/sh

PROCESS=named
PROCESSPATH="/usr/sbin/named"

if [ "`ps -A | grep "$PROCESS"`" = "" ]; then
echo Starting process
$PROCESSPATH &
fi

--- snip ---

If the process forks as a deamon by itself, do not put the "&" after $PROCESSPATH.

by jrtietsort

I'm not sure why you need the script, but just wanted you to know that the 'init' daemon will do this for you. Check out the man page for 'inittab' and setup your process to respawn.

This discussion is closed to new replies.