Hi, I'm not good in scripting, maybe someone can help me.
I need to delete the lines that contains the last month date from a text file. Each line has the following date format:
[08/Nov/2001:17:06:58 +0300]
So the script should check the actual month, and delete all the lines that contains the past month. The script runs once a month, of course.
As you can see, I know what I need but I don't know how to do it.
If you know how to do it, please, enlight me with you knowledge....
Thanks:confused:
Hi,
This is fairly easy to accomplish.
You could use grep.
First copy your logfile to a *.old filename.
$ cp logfile logfile.old
Then grep -v to get rid of undesirable lines containing the pattern you want to delete.
$ cat logfile.old |grep -v "Nov/2001" > logfile
OR
Better, you can just save your logs to *.old1, *.old2 when the first day of the month arrives, run from cron.
# minutes (0-59) hours (0-23) dates (1-31) months (1-12) days (0-6)
0 0 1 * * /some/log/cleahup.sh
$ vi cleanup.sh
cp /some/log/file1 /some/log/file2
cp /some/log/file /some/log/file1
> /some/log/file

OK I will use the second option. It was more simple than I thought, thank you.