Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-23-2003, 11:09 PM   #1
Registered: Mar 2003
Location: Rockford, Illinois
Distribution: Slackware Debian
Posts: 86

Rep: Reputation: 15
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]): FTP session opened.
... // more of the same
Sep 21 14:45:48 teacup proftpd[766] teacup.localhost (localhost[]): 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?
Old 09-24-2003, 01:36 AM   #2
Registered: Aug 2003
Location: Suprisingly in Heaven
Posts: 223

Rep: Reputation: 33
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[]):"){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 ....

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[]):"){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

Last edited by SaTaN; 09-24-2003 at 01:51 AM.
Old 09-24-2003, 11:32 AM   #3
Registered: Mar 2003
Location: Rockford, Illinois
Distribution: Slackware Debian
Posts: 86

Original Poster
Rep: Reputation: 15


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create log file from script fotoguy Programming 12 03-27-2012 06:39 AM
user log in and autoruns script rharris72 Programming 1 11-21-2005 09:14 AM
log on (script?) problem gsabcuk General 2 06-10-2005 05:06 AM
init script won't run at log-off dimangi Linux - Newbie 1 10-29-2003 02:19 AM
A live log monitor script ? ifm Linux - Software 1 07-19-2002 02:54 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:14 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration