LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   results of "top" when run from cron (https://www.linuxquestions.org/questions/linux-software-2/results-of-top-when-run-from-cron-609150/)

lothario 12-26-2007 02:51 AM

results of "top" when run from cron
 
I have a bash script "/home/me/test" that contains:

...
top -c -b -n 1 > /tmp/temp1.txt
...


When I run this script via command line, the results are fine:

5981 www-data 18 0 23872 8788 4192 S 0.0 2.0 0:19.63 /usr/sbin/apache2 -k start
5982 www-data 15 0 23876 8936 4164 S 0.0 2.0 0:19.52 /usr/sbin/apache2 -k start
5983 www-data 15 0 23888 8932 4144 S 0.0 2.0 0:13.26 /usr/sbin/apache2 -k start
5984 www-data 15 0 23884 8928 4144 S 0.0 2.0 0:38.66 /usr/sbin/apache2 -k start
5993 www-data 15 0 23888 8936 4148 S 0.0 2.0 0:13.05 /usr/sbin/apache2 -k start


When this script runs via cron, the results are cut off at the end of each line after 80 characters:

5981 www-data 18 0 23872 8788 4192 S 0.0 2.0 0:19.63 /usr/sbin/apache2 -
5982 www-data 15 0 23876 8936 4164 S 0.0 2.0 0:19.52 /usr/sbin/apache2 -
5983 www-data 15 0 23888 8932 4144 S 0.0 2.0 0:13.21 /usr/sbin/apache2 -
5984 www-data 15 0 23884 8928 4144 S 0.0 2.0 0:38.66 /usr/sbin/apache2 -
5993 www-data 15 0 23888 8936 4148 S 0.0 2.0 0:13.05 /usr/sbin/apache2 -


So how can I prevent this cut off at 80 characters?
How should I modify the "/home/me/test" script?

colucix 12-26-2007 03:24 AM

On my system (using xterm) the output of top matches the current width of the terminal. The width is dynamically stored in the environment variable COLUMNS, so you can try to set it manually when launching a cron job, as in
Code:

5 * * * * /usr/bin/env COLUMNS=127 /usr/bin/top -c -b -n 1 > /tmp/temp1.txt

lothario 12-26-2007 03:37 AM

That works.
Thanks.


All times are GMT -5. The time now is 06:14 PM.