LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-08-2005, 02:49 PM   #1
kt8993
Member
 
Registered: Sep 2004
Posts: 34

Rep: Reputation: 15
Talking Scripts to check if a process is running


Hi All,
I am using Mandrake10.1. I am running amule all the time, but sometimes this program ended unexpectedly while I was away.

How do I write a script to check if this process is running, if not run the process?
How do I automatically run this script every hour?

Thanks.
 
Old 07-08-2005, 02:57 PM   #2
fouldsy
Senior Member
 
Registered: Jan 2002
Location: St Louis, MO
Distribution: Ubuntu
Posts: 1,284

Rep: Reputation: 47
There's a nifty tool called "pidof" that basically runs through and checks for a running serivce and returns the pid of it. It's the same as running ps aux | grep amule and nothing the pid of it. I'm no expert, but something like:

Code:
$service=0
$service=pidof amule

if($service==0) {
    /path/to/amule
}
and then setup a cronjob to run this every 30 minutes. I don't know much about bash scripting, but that's the basic control loop, but the syntax is propbably wrong for bash. Have a read on bash scripting and cronttab for scheduling events. Shouldn't be too hard though.
 
Old 07-09-2005, 05:11 PM   #3
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
Code:
#!/bin/bash
while true
do
    [ ! /sbin/pidof amule ] && /path/to/amule
    sleep 3600
done
 
Old 07-09-2005, 05:32 PM   #4
fouldsy
Senior Member
 
Registered: Jan 2002
Location: St Louis, MO
Distribution: Ubuntu
Posts: 1,284

Rep: Reputation: 47
Shows how good my bash scripting is - think I'll stick to PHP! Least I was along the right lines :-)
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Obtain ip address and check for running process via Bash Script? xconspirisist Programming 10 09-12-2008 01:18 PM
Scripts tp Check Network Connections assyrian47 Programming 2 06-18-2004 01:19 PM
script to check if process is dead or running rspurlock *BSD 6 04-12-2004 11:32 PM
[script] check for a running process mikshaw Linux - Software 2 01-13-2004 08:33 PM
program to check to make sure a process is running? IceNineJon Linux - Software 7 08-06-2003 02:07 PM


All times are GMT -5. The time now is 11:32 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 Google+: linuxquestions
Open Source Consulting | Domain Registration