LinuxQuestions.org
Register a domain and help support LQ
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 03-20-2014, 09:47 AM   #1
enchant1
LQ Newbie
 
Registered: Mar 2014
Posts: 3

Rep: Reputation: Disabled
Outputting to a size-restricted file


Many years ago, I worked at Bolt, Beranek & Newman, and their unix machines had a utility called "roll". I suspect it was written by them for their machines, but it was a handy utility.

Basically, if you wanted to pipe output of a program into a file, but you didn't want that file to get massive, you'd do it something like this:

myprogram | roll -f log.out -size 500k

Once the file reached 500Kb, it would start overwriting itself, keeping only the most recent 500Kb of data.

Does something like this exist on standard Linux boxes today?
 
Old 03-20-2014, 06:04 PM   #2
Philip Lacroix
Member
 
Registered: Jun 2012
Distribution: Slackware, FreeBSD
Posts: 173

Rep: Reputation: 82
Hi,

what about using tail? There's the option --bytes=<size>

Code:
# yrprogram >> log.out && tail --bytes=500K log.out > log.tmp && mv log.tmp log.out
Regards
 
Old 03-20-2014, 06:09 PM   #3
enchant1
LQ Newbie
 
Registered: Mar 2014
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thanks, but the problem is to keep large forgotten files from getting too large.
 
Old 03-20-2014, 06:25 PM   #4
Philip Lacroix
Member
 
Registered: Jun 2012
Distribution: Slackware, FreeBSD
Posts: 173

Rep: Reputation: 82
Doesn't the above keep log.out from exceeding 500Kb? Of course this doesn't prevent a _single_ output of yrprogram from temporarily making it exceed that size.

Last edited by Philip Lacroix; 03-20-2014 at 06:34 PM.
 
Old 03-21-2014, 11:21 AM   #5
enchant1
LQ Newbie
 
Registered: Mar 2014
Posts: 3

Original Poster
Rep: Reputation: Disabled
Sorry, I think I misunderstood what you were saying the first time around. I'll give that a try.

Thanks!
 
Old 03-22-2014, 04:58 AM   #6
Philip Lacroix
Member
 
Registered: Jun 2012
Distribution: Slackware, FreeBSD
Posts: 173

Rep: Reputation: 82
Quote:
Originally Posted by enchant1 View Post
Sorry, I think I misunderstood what you were saying the first time around.
Don't worry. If you need to handle log files you might want to consider logrotate, which should be included in every distribution. It can handle files size as well.

Code:
# man logrotate
Cheers
 
  


Reply


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
Outputting to a fake file crofty13 Linux - Software 2 07-14-2006 07:17 PM
outputting data from a directory to a text file? minm Linux - Newbie 2 12-19-2004 06:46 PM
outputting firewall messages to a file instead if stdout schatoor Linux - Networking 2 06-25-2004 11:40 AM
reading a text file and outputting to another. Hardw1re Programming 28 11-03-2003 08:51 AM
outputting ftp contents to file kubicon Linux - Networking 2 09-15-2003 02:01 PM


All times are GMT -5. The time now is 11:32 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration