Click to See Complete Forum and Search --> : script for checking for a running process


scoobydope
02-21-2001, 04:26 PM
this is obviously for a cron job, but i have noticed that arpwatch will stop running for some reason when cron runs through its nightly duties.

I haven't figured out what is stopping it yet, but would like to just add an hourly cron entry to check to see if its running and then start it up if its not.

The starting it up is no problem, but the script line to check for it is confusing me.

basically i understand the idea, but don't know the language:

ps -aux |grep -v grep|grep arp

if the results of this are nothing, then run the script.
But what is the script line for "if the results of this are nothing"?

3Wheels
02-21-2001, 04:54 PM
testit.ksh:
#! /bin/ksh
ps -aux | grep -v grep | grep -s farkles > /tmp/ps.out 2> /tmp/ps.err
if [ $? -eq 1 ]
then
echo "Need to restart farkles"
else
echo "farkles is running"
fi

error27
02-22-2001, 02:26 AM
Maybe instead of doing a:
ps -aux
you should use a:
ps U root | grep -v grep | grep -s "/usr/sbin/arp "

That way if a user is playing a tremendous game of "Snarple Frog" the script won't be confused.

here is a bash version of the ksh script mattmorrow gave.

#----------------------
#!/bin/bash

if !(ps U root |grep -v grep| grep -s "/usr/sbin/arp ") ; then echo "Need to restart arp" ; fi

#----------------------

jemfinch
02-22-2001, 04:42 AM
It's highly likely that the init you're running has the ability to respawn processes that die.

I have no idea how to configure it to do that, though.

Jeremy