Reputation: 21
I wrote this shell script named example.sh on Linux.
#!/bin/sh
TOPLOG=/tmp/top.log
date +%H:%M:%S >> ${TOPLOG}
top -b -c -n 1 |head -n 8 |tail -n 2 >> ${TOPLOG}
echo >> ${TOPLOG}
When I run it with the command "sh /tmp/example.sh", texts in top.log is like
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
17980 cybereas 20 0 1478m 73m 18m S 2.0 0.5 1360:59 /opt/cybereason/sensor/bin/cybereason-sensor
However, when I run this script with this crontab
*/1 * * * * sh /tmp/example.sh
texts in top.log is shown like
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
17980 cybereas 20 0 1478m 73m 18m S 2.0 0.5 1360:59 /opt/cybereason/sen
The output of "COMMAND" is omitted when it is a little long.
Is there any solution for this? I appretiate for any idea. Thank you.
Upvotes: 1
Views: 406
Reputation: 38985
you can try command like this:
COLUMNS=8000 top -c -d1 -n2|fold -w 230 -s
Upvotes: 0
Reputation: 5251
When not printing to a regular file, and not a terminal (>> "$TOPLOG"
), top
is truncating output to the standard terminal width of 80 columns.
If your top
has the -w
switch, add -w 512
for a larger maximum width.
Upvotes: 0