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

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.

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

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.

1 Like

Thanks...........That solved my problem......:b: