Operating System - HP-UX
1833777 Members
2055 Online
110063 Solutions
New Discussion

Re: trimming files created by sar...

 
Denise_22
Advisor

trimming files created by sar...

I got a few cron jobs running that collect system statistics via the sar command. These files are becoming quite large and would like to trim them. I believe I read somewhere where the cat command can do this? Is there any other way besides this? thanks.
carpe diem
4 REPLIES 4
doug mielke
Respected Contributor

Re: trimming files created by sar...

You can tail -x filename > filename (or head) where x is number of lines. There is a relatively small limit for x ( based on chars?)

Alternativly, if you make use of the /var/adm/sa directory for sar history, you can finfigure how many days of info ( number of files) to keep.
doug mielke
Respected Contributor

Re: trimming files created by sar...

..read finfigure as configure
Brian Bergstrand
Honored Contributor

Re: trimming files created by sar...

Add the following to your shell script to archive the files and then zero them

cp sar.out sar.out.`date +'%Y%m%d'`
/usr/contrib/bin/gzip sar.out.`date +'%Y%m%d'`
> sar.out

This way you don't lose any data.

HTH.
John Dvorchak
Honored Contributor

Re: trimming files created by sar...

I am a little fuzzy about why you want to trim them. If the data is not needed then why are you collecting the data to begin with? Just don't collect so much of it. Perhaps you are just looking for data that covers the specified "Peak" periods. Then set up your cron jobs to only run at those times.

If what you are looking for is a way to get rid of files older than a week, or any period you choose, then that is a different thing than you are asking. If you want to collect data all day but only keep a few days worth then:

find /var/adm/sa -type f -mtime +7 -exec rm {} \:

This you can put in cron and have it run daily to get rid of the type f(ile) that are older than 7 days (mtime +7).

Good luck.
If it has wheels or a skirt, you can't afford it.