LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 09-25-2002, 05:33 AM   #1
gborrageiro
LQ Newbie
 
Registered: Sep 2002
Posts: 2

Rep: Reputation: 0
Question cron job to restart process if dead


hello all,

Please could someone assist me with a rather simple bash scripting problem I'm having?

I'm trying to create a script to run in cron that will automatically restart a process if it finds that the process has died.

lets assume the following:
1) the program is snort

I tried the following a script, but it does not work.

*********************************************************
#!/bin/bash

if `ps -ef |grep -v grep |grep snort |awk {'print $8'} != "/usr/sbin/snort"
then
snort -c /etc/snort/snort/snort.conf -D -l /var/log/snort
fi
********************************************************
It does'nt work,

If I try:
********************************************************
#!/bin/bash
if [ -n `ps -ef |grep -v grep| grep snort| awk {'print $8'}` ]
then
snort -c /etc/snort/snort/snort.conf -D -l /var/log/snort
fi
*********************************************************

that does'nt work either.

Can someone pickout my obvious mistakes?

Kind Regards,

Gabrieil
 
Old 09-25-2002, 06:59 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 21,592
Blog Entries: 47

Rep: Reputation: 1408Reputation: 1408Reputation: 1408Reputation: 1408Reputation: 1408Reputation: 1408Reputation: 1408Reputation: 1408Reputation: 1408Reputation: 1408
Re: cron job to restart process if dead

Dunno, but here's what I'd try:
#!/bin/bash
# If you don't have /sbin/pidof linked to /sbin/killall5:
# Mimic pidof's "-s" using head -n 1, after all we don't expect multiple snorts running
PID=$(/bin/ps ax | grep snort | grep -v grep | awk {'print $1'} | head -n 1)
# else
# PID=$(/sbin/pidof -s /usr/bin/snort)
if [ "$PID" = "" ]; then <remove-stale-pid command>; <restart command>; fi

Last edited by unSpawn; 09-25-2002 at 07:02 AM.
 
Old 09-25-2002, 07:52 AM   #3
gborrageiro
LQ Newbie
 
Registered: Sep 2002
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks,

but that still does'nt test to see if the daemon has died.
I only want the script to execute if the daemon is dead, identiified by the absense of a running PID.


regards,

Gabriel
 
Old 09-25-2002, 11:55 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 21,592
Blog Entries: 47

Rep: Reputation: 1408Reputation: 1408Reputation: 1408Reputation: 1408Reputation: 1408Reputation: 1408Reputation: 1408Reputation: 1408Reputation: 1408Reputation: 1408
Ok, then run the script (w/o quotes) as: "sh -x <scriptname>"
and show me how this does *fill* the PID variable if there is *no* PID for snort to be found...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cron Job petenyce Linux - Newbie 5 10-11-2005 04:03 PM
Crond Dead But Subsys Locked, cannot restart cron services jmm8142 Linux - Software 4 05-23-2005 12:41 PM
Cron job to check/restart network connection? mac_phil Linux - Networking 6 09-01-2004 01:51 PM
crontab job to restart tomcat... barbean Programming 0 11-17-2003 12:58 AM
Cron Job imanahmadi Linux - Newbie 1 07-03-2003 11:39 PM


All times are GMT -5. The time now is 09:52 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration