If this is an actual service, it will probably run as root and it would be better if you used the "service" command or /etc/init.d/ startup script (or a rc* script in SuSE) to start the script. The scripts to start a service will have a status argument that will allow you to monitor whether the service is running.
You can use the return value of the script to decide whether it needs to be started or not.
For example:
Code:
/usr/sbin/rcsmb status >/dev/null && echo running || /usr/sbin/rcsmb start
Starting a service needs to be done as root, so you might want to create a cron job to run periodically. You will need to redirect output (both stdin and stdout) to /dev/null or a log for a cron job.
In my example the part between the && and || is superfluous and you could do without it unless you wanted to log success. But that would build up a large log file unnecessarily.
Code:
/usr/sbin/rcmysql status 2&>1 1>/dev/null || /usr/sbin/rcmysql start
Code:
jschiwal@hpmedia:~> sudo /sbin/service mysql status && echo running || echo notrunning
Checking for service MySQL: running
running
jschiwal@hpmedia:~> sudo /sbin/service xfs status && echo running || echo notrunning
Checking for X Font Server: unused
notrunning