Jump to content
EduGeek EdSec 2026 is Go! 27th Oct in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×

Need a command line utility to truncate or shrink a log file


Recommended Posts

Posted
I'm writing a script to backup some files on a daily basis. The script handles getting rid of old backups automatically, but for ease of monitoring, results go into a single summary log. This log will obviosuly continue to grow over time and I want to be able to shrink the log when it reaches a certain size (let's say 1Mb). I could code this myself, but there must be something out there.....
Posted

Andy,

 

What I do in my kix scripts when I open the logfile is:

 

$ = RedirectOutput($logfile, GetFileSize($logfile) > 51200)

 

The second paramater determines whether the file is appended to or overwritten. In the case above, it is appended to until it reaches 50k. If it's 50k+, the content gets overwritten.

 

It may not be exactly what you want as you lose the previous content, but if you're logging this elsewhere and this is only a summary it may be an option to consider.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...