|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
A question
Hi, I'm new to unix and got struck here.Can any one help me out.My question is .. is the command Code:
if [ ps -ef |grep "any pid"]; then echo "do some stuff" fi correct? Thanks in advance abhijeet Last edited by Scott; 02-07-2012 at 06:03 AM.. Reason: Please use code tags, and a more useful subject for your threads. Thanks. |
| Sponsored Links | |
|
|
|
#2
|
||||
|
||||
|
Code:
ps -ef | grep -q "any pid"
if [ $? -eq 0 ]
then
echo "do some stuff"
fi |
| Sponsored Links | ||
|
|
|
#3
|
|||
|
|||
|
Thanks Balajesuri!!
![]() Can you throw some light on the syntax too.. it would be helpfull. |
|
#4
|
||||
|
||||
|
Code:
ps -ef | grep -q "any pid" => Search for "any pid" from the output of ps -ef but don't display any output (-q takes care of this). if [ $? -eq 0 ] => $? is the exit status of last command executed. $? is set to 0 if the last command executed is a success. |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
suppose i want to grep only that PIDs which have its parrent pid as 1, then what should i do?
|
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
Something similar... Code:
if pgrep "some_pid" >/dev/null then echo "do some stuff" fi pgrep = process id grep --ahamed |
| The Following 2 Users Say Thank You to ahamed101 For This Useful Post: | ||
Abhijeet_Atti (02-07-2012), Prasannag87 (02-07-2012) | ||
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Thanks Ahamed!!
can you help me little more.. ![]() suppose we have a pid= 15641 and it PPID =1 i want to check if this process is there i'll do some stuff.. now how would i check Last edited by Scott; 02-07-2012 at 05:51 AM.. Reason: Removed "bump"; previous post was in moderation queue. Patience! |
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| New to Awk question... | treeNinja | Shell Programming and Scripting | 2 | 09-21-2010 08:11 PM |
| ***question on sed*** | mahenderkrao | UNIX for Advanced & Expert Users | 3 | 06-19-2008 03:59 AM |
| Another question??? | skyineyes | UNIX for Dummies Questions & Answers | 1 | 06-12-2008 01:09 AM |
| I have a question... | Jerry_wang | Linux | 2 | 06-25-2005 09:59 AM |
| sed question | Docboyeee | Shell Programming and Scripting | 2 | 04-06-2005 08:54 PM |
|
|