LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   log cleanup script (https://www.linuxquestions.org/questions/programming-9/log-cleanup-script-96160/)

teacup 09-23-2003 11:09 PM

log cleanup script
 
How do I write a cron script that will remove all local connections from my proftd.log and my xferlog files? The lines in the proftpd.log look like this:

Sep 15 21:25:28 teacup proftpd[948] teacup.localhost (12-345-678-91.domain.com[12.345.678.91]): FTP session opened.
...
... // more of the same
...
Sep 21 14:45:48 teacup proftpd[766] teacup.localhost (localhost[127.0.0.1]): FTP session opened.

I want to remove all lines that look like the last one in the file (all the lines with localhost connecting to the server). How would I do this sort of thing?

SaTaN 09-24-2003 01:36 AM

type "crontab -e" on the command prompt...
A file will be opened. Place this line in that file



0 0 * * * cat file | awk '{if($7!="(localhost[127.0.0.1]):"){for(i=1;i<=NF;i++){printf $i" "}print""}}' > new_file



file is the path to the proftd.log and the new_file is where you
want it to be stored......

P.S :- This code will be executed at 00:00:00 time everday ....

<edit>
You shouldn't use same file as both "file" and "new_file' . If you want to store in the same log file then,

0 0 * * * cat file | awk '{if($7!="(localhost[127.0.0.1]):"){for(i=1;i<=NF;i++){printf $i" "}print""}}' ; cp new_file file ; rm -f new_file

You should give the full paths to file and new_file


teacup 09-24-2003 11:32 AM

Thanks!


All times are GMT -5. The time now is 02:14 AM.