The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
joining command results, and substitution ncatdesigner Shell Programming and Scripting 6 04-17-2008 08:37 AM
My ps -ef|grep command results are chopped off bsp18974 UNIX for Dummies Questions & Answers 1 08-14-2007 07:35 AM
New iteration of for-loop without incrementing? jeriryan87 Shell Programming and Scripting 0 07-02-2007 11:13 AM
How to output the results of the AT command - properly! SpanishPassion UNIX for Dummies Questions & Answers 4 12-04-2005 07:27 PM
renaming variable between iteration Nicol Shell Programming and Scripting 2 04-06-2005 05:04 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-11-2008
Registered User
 

Join Date: Jun 2008
Posts: 3
Iteration through the results from a unix command

Hi,

I am using a command "ps -ef | grep identify" which results more than 1 results. Actually I need to get the time from each of them , compare with the current date and conditionally stop a process.

The problem I am facing is to iterate through the results getting from the command. Please Help me regarding this script.
Plz let me know if my problem is not clear....


Thanks
Devi
Reply With Quote
Forum Sponsor
  #2  
Old 06-11-2008
Wolja's Avatar
Registered User
 

Join Date: Feb 2002
Posts: 15
Quote:
Originally Posted by deviprasad83 View Post
Hi,

I am using a command "ps -ef | grep identify" which results more than 1 results. Actually I need to get the time from each of them , compare with the current date and conditionally stop a process.

The problem I am facing is to iterate through the results getting from the command. Please Help me regarding this script.
Plz let me know if my problem is not clear....


Thanks
Devi
If you are looking for things today it won't be as easy as ps helpfully, Not, doesn't add the Month and Date to the output for processes started today .

If for earleir than today than ps -ef | grep identify | grep 'date eg Jun 11' would give you those processes. If you want to deal with them one at a time and kill them then personally I'd write them to a file, ps -ef | grep identify | grep ' Jun 11' | awk 'print $2' > pid_list.txt then using a for loop or a while loop process each and issue a kill command.
Reply With Quote
  #3  
Old 06-11-2008
Registered User
 

Join Date: Jun 2008
Posts: 3
Thanks 4 the response.....Actually using the command " ps -ef | grep identify " gives the following result:

app 18598 17757 0 13:33 pts/1 00:00:00 grep identify
mm 34567 67444 1 12:22 pts/1 00:00:00 grep identify

I want to get one line at a time and the process further 4 the requirements......using for loop splits this line with the whitespace.

Plz help further....

thanks
Reply With Quote
  #4  
Old 06-12-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Code:
ps -ef | grep identify |
while read line; do
  # for example, split on whitespace once we have one line
  set -- $line
  case $5 in 13:33) echo "$@";; esac  # just as an example
done
You can use a for loop as well if you set IFS to just a newline, but while is what I would recommend.
Reply With Quote
  #5  
Old 06-12-2008
Registered User
 

Join Date: Jun 2008
Posts: 3
Thanks...........That solved my problem......
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:25 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0