LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-13-2004, 07:24 PM   #1
mikshaw
LQ Addict
 
Registered: Dec 2003
Location: Maine, USA
Distribution: Slackware/SuSE/DSL
Posts: 1,320

Rep: Reputation: 45
Question [script] check for a running process


I'm wondering if there is a more efficient/compatible way to do this:
Code:
if [ -n "$(ps -A | grep root-tail)" ]; then
   echo "root-tail is already running"
else
   root-tail -f -g 120x30+8+8 ${HOME}/log/console,brown,'messages'
fi
It works for me in a bash script, but I understand $(command) does not work in other shells.
I tried
Code:
if [ -n `ps -A | grep root-tail` ]
but it doesn't seem to work.

Thanks for any help.
 
Old 01-13-2004, 08:21 PM   #2
lyle_s
Member
 
Registered: Jul 2003
Distribution: Slackware
Posts: 392

Rep: Reputation: 55
You're using command substitution, which substitutes the standard output of a command. All you're looking for if the return value of the command.

Code:
if ps -C root-tail > /dev/null; then
	echo "root-tail is already running"
else
	root-tail -f -g 120x30+8+8 ${HOME}/log/console,brown,'messages'
fi
Lyle
 
Old 01-13-2004, 08:33 PM   #3
mikshaw
LQ Addict
 
Registered: Dec 2003
Location: Maine, USA
Distribution: Slackware/SuSE/DSL
Posts: 1,320

Original Poster
Rep: Reputation: 45
Hmmm...that looks interesting.
However, ps -C <command> still returns "PID TTY TIME CMD" even if the specified process isn't running, which is why I added the grep.
So maybe if `ps -A | grep root-tail` > /dev/null; would work?


Oh...it seems the "PID TTY TIME CMD" doesn't have any effect, so it works fine.
Thank you

Last edited by mikshaw; 01-13-2004 at 09:14 PM.
 
  


Reply



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
How can I check to see if a script is running? slick_willie Programming 13 03-16-2007 10:18 AM
Scripts to check if a process is running kt8993 Programming 3 07-09-2005 05:32 PM
script to check if process is dead or running rspurlock *BSD 6 04-12-2004 11:32 PM
program to check to make sure a process is running? IceNineJon Linux - Software 7 08-06-2003 02:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:29 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration