I have this command:
top -n 14400 -a -b -d 1 > /toplogfile.txt
I want to make a script which is run by
cron every day to capture top output, and if it is possible
gzip the output file after the script finished.
How can I implement this?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
top -n 1 will run top for 1 iteration. You can direct that output to a file and compress it using a simple shell script like this:
top -b -n 1 | gzip -c > top_output.gz
top -b specifies that you want top to run in "Batch Mode" which eliminates all of the control characters that top normally uses to format the output.
-n 1 tell top to run 1 iteration
gzip -c tells gzip to compress the data it is being sent