i am not an avid unix user and trying to resolve an issue which seems to be too tough for me..but would be way too easy for ya'll.
I am trying to pull the logs for last 24 hours using the date command. It works perfect with grep using this syntax: grep "logs" messages | grep "Jan 6", but I want this to run as a script so that I can set up a cron for this activity.
Below mentioned syntax is what I am trying but its not correct that is what I've established so far. please help. Thanx
#!/bin/bash
DATE=$(date +"%m-%d-%Y")
grep "logs"/var/log/messages | grep DATE > /var/tmp/logs
I think this is what you mean. If the word "logs" appears in the lines you wish to extract, then I'm wrong.
Also I've tested with a different output filename in case there is a directory called /var/tmp/logs . The output filename is your choice.
The important part is the format of the output of the "date" command (yours produces mm-dd-yy format).
Example of the log: It contains the date parameter in the beginning of the logs as well..
Jan 6 11:22:39 192.168.0.3 Jan 06 19:22:38 2011 vikbenq
I reiterate if I run the grep command it works perfect and I only get the logs for Jan 6 however I want to use this as a script where it should run everyday and pull the logs for only last 24 Hours.
i.e. If it ran today it would pull logs only for Jan 6 and if it runs tomorrow it would pull logs from Jan 7 and so on...