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....
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.
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.