Operating System - HP-UX
1832932 Members
3369 Online
110048 Solutions
New Discussion

Re: script for top output every week

 
SOLVED
Go to solution
GSB_3
Frequent Advisor

script for top output every week

hi,

I need a script which can send top output to one file every week on monday and keep four weeks data.

Pls help

Thanks
4 REPLIES 4
Shrikant Lavhate
Esteemed Contributor

Re: script for top output every week

Hi there,

To send a top output to a file you can use redirector.

#top >>/tmp/top.out

For every week on monday make entry of the scipt into crontab with timestamp as:

* * * * 1

So, the rough entry in cron will look like :

* * * * 1 path_of_script

In above things each time top output will be append at the last of the /tmp/top/out file. If you want to create new file to each days output then it will need some looping logic into script.
Will it remain a personal, if I broadcast it here!
Dennis Handly
Acclaimed Contributor
Solution

Re: script for top output every week

>Shrikant: To send a top output to a file you can use redirector.

For top(1), you should be using -f: top -f file

To keep 4 weeks:
top -f file.0
mv file.3 file.4
mv file.2 file.3
mv file.1 file.2
mv file.0 file.1

You need to seed the script for the first time.

>* * * * 1 path_of_script

This runs top every minute. And unless you pass options to top or use -f, it won't stop.

So if you want to run it once at 1 am:
00 01 * * 1 path_of_script

So GSB needs to define what he wants.

GSB_3
Frequent Advisor

Re: script for top output every week

Thanks Dennis and shrikant.

It helped.
Shrikant Lavhate
Esteemed Contributor

Re: script for top output every week

Thanks Dennis for that minute option. I just slipped their. :D
Will it remain a personal, if I broadcast it here!