LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-13-2007, 01:17 AM   #1
blu_alchemist
Member
 
Registered: Jun 2007
Location: Canada
Distribution: Fedora Core 7
Posts: 31

Rep: Reputation: 15
Truncating Script


I have a server log that outputs
Code:
`/bin/date +%H%M` `/bin/date +%d` $SDB $SDC $SDD $SDE"
and the log file looks:
Code:
0540 13 33 33 35 36
0541 13 33 33 35 35
0542 13 33 33 35 36
0543 13 33 33 35 35
0544 13 32 33 35 35
0545 13 33 33 35 36
0546 13 33 33 35 36
0547 13 33 33 35 36
0548 13 33 33 35 35
The second value is the day in 1-31 format. Now I want to truncate the file at midnight so I only have that days data in this specific log file.

The original log file has thousands of entries that spans weeks and I am looking for a script that will take massive.log and take only the latest days info and make daily.log.

Ex:
Code:
cat massive.log | grep '/bin/date +%d' > daily.log
Something along that line would work perfectly EXCEPT I cannot use the '/bin/date' part in the command. I have seen many console examples such as

Code:
apt-get remove -f 'dpkg -l | grep i18n'
As a way to remove the searched packages but once again the console says cannot find 'dpkg -l | grep i18n' is their something obvious im missing??
 
Old 09-13-2007, 02:38 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Code:
cat massive.log | grep '/bin/date +%d' > daily.log
The correct syntax is with back quotes instead of single quotes
Code:
cat massive.log | grep `/bin/date +%d` > daily.log
Anyway, take in mind that this will match any line containing the number of the current day at any position in the file. Maybe you will not get the expected result.
 
Old 09-13-2007, 04:52 PM   #3
blu_alchemist
Member
 
Registered: Jun 2007
Location: Canada
Distribution: Fedora Core 7
Posts: 31

Original Poster
Rep: Reputation: 15
All these years of computer use and I just realized theirs a '`' under that their tilde key...

Yea theirs that small problem of any times with 13xx, x13x, xx13 are also included in the file.

awk '{print $2}' would only include the second line but cut out all the others while doing so. An if statement might be able to filter out all non 2 digit numbers but im not so good at automatic scripting.
 
Old 09-13-2007, 05:44 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by blu_alchemist View Post
Now I want to truncate the file at midnight so I only have that days data in this specific log file.
Wouldn't it be easier to logrotate the logfile then? Or zap the log and restart this service?
 
Old 09-13-2007, 06:40 PM   #5
blu_alchemist
Member
 
Registered: Jun 2007
Location: Canada
Distribution: Fedora Core 7
Posts: 31

Original Poster
Rep: Reputation: 15
I prefer to have the absolute minimum amount of packages installed on my servers and currently I have 100% usable systems in under 500mb. Makes things very affordable to run a raid 1+0 system with solid state media for maximum os performance.

I agree that my current method of manging log files is grossly inadequate but I was still hoping for an answer to this post as it will solve several other issues.

Im reading up on log rotate and if it will suit my needs I may add it to my pkg list but Im unsure if it can manage a massive 45000line log file and separate it into daily updates every hour.

Maybe someone knows of a full management suit that provides, CPU/swap/mem/thread/eth-traffic/drive and sys temperatures and would make log files for monthly(hourly samples) weekly(30min samples) daily(5min samples) and yet graph them onto an html page without using python, or a PNG image.
 
  


Reply



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
shell script - truncating filenames mr_scary Programming 3 09-04-2006 02:50 PM
truncating output of ls command chucker8 Linux - Newbie 2 03-02-2006 10:01 AM
Samba truncating files to 0 bytes KimVette Linux - Networking 6 01-30-2005 06:42 PM
Truncating trailing characters liguorir Programming 0 05-23-2004 04:00 AM
Truncating a string nkendrick Linux - General 5 11-29-2003 09:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:22 AM.

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