LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-26-2007, 02:51 AM   #1
lothario
Member
 
Registered: Apr 2004
Posts: 340

Rep: Reputation: 30
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?
 
Old 12-26-2007, 03:24 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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
 
Old 12-26-2007, 03:37 AM   #3
lothario
Member
 
Registered: Apr 2004
Posts: 340

Original Poster
Rep: Reputation: 30
That works.
Thanks.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
info to run "cu" command from cron tcore Mandriva 5 12-27-2018 11:34 AM
simple "echo > qbc" cron jobs doesn't run shole Linux - Newbie 3 09-23-2006 02:09 PM
How do I make a cron job run "every two weeks"? Seventh Linux - Newbie 12 01-13-2006 11:55 AM
"Successful install" results in "Boot device not found" slackr007 Fedora 2 06-21-2005 04:05 PM
system("top") in a C program giving problems when the C prg is run by cron rags2k Programming 1 09-02-2004 03:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration