kde-head Posted March 18, 2004 Report Share Posted March 18, 2004 You probably already know that if you want to grep your messages log for messages on a certain date, you would cd to /var/log and do grep "Mar 17" messages But say you wanted to automate this, maybe looking for specific message types everyday (which could be either mailed to you or outputted to a report)? Enter command substitution: grep "$(date +"%b %d")" /var/log/messages the bit between the quotes executes the date command and returns the date in the format "Mar 17" say - this is then passed into the grep. Quote Link to comment Share on other sites More sharing options...
aru Posted March 20, 2004 Report Share Posted March 20, 2004 A little addition to your tip. If you are not english speaker, so you have a different locale set, you probably won't see anything if you run the command: grep "$(date +"%b %d")" /var/log/messages because date will return the output in your locale format, while the logs are usually in POSIX format. To avoid this, just do: grep "$(LC_ALL=POSIX date +"%b %d")" /var/log/messages Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.