Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to isolate log files from the grep command

Status
Not open for further replies.

SuaveRick

Programmer
Apr 12, 2004
142
CA
Hey there,
I need to check the running processes for a stuck archive process that sometimes gets hung up on a log file. Here is what I have:

while read processes
do
echo "Checking $processes for hung file"
ps -ef | grep "$processes" > gzipcheck.dat
status2=`fgrep -v "grep" gzipcheck.dat`
if [ -n "$status2" ]
then
echo "$status2"
else
echo "not hung"
fi
done < processes.dat

It works fine but it returns processes it should. Example: one of the log files I search for is simply 'ms.ddmmyy_hhmmss.log' what I would like to do is have the ps -ef | grep "$processes" > gzipcheck.dat line check for processes that have a .log in the name... but I can't figure out how to get the grep command to search for something like "$processes" ending with a .log.

Any ideas?
 
Simply this ?
grep "${processes}\.log"
Or this ?
grep "${processes}.*\.log"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Well that gives me back an empty variable like I'm looking for, I'll have to produce my problem and see if it works. Thanks very much!! If you don't mind, could you explaine the difference between the \.log and .*\log, I think I know the diff with the wildcards and repeating characters but I want to make sure.

Thanks!!!!
 
[tt]"${processes}\.log"[/tt]
Search for value of $process immediatly followed by .log
[tt]"${processes}.*\.log"[/tt]
Search for value of $process followed by any char(s) then .log

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Excellent, the second option is what I thought I needed and that's it for sure.

Thanks very much for the help, I appreciate it!

Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top