Operating System - Linux
1825771 Members
2209 Online
109687 Solutions
New Discussion

Re: "top -c" doesn't work from under cron

 
Vitaly Karasik_1
Honored Contributor

"top -c" doesn't work from under cron

I want to save "top -c" output into a file for parsing it.

I use this command:
/usr/bin/top -bc -n1 >/tmp/top.out

This works nice from a command line, but when I run it under cron, "top" output is cutted to 80 symbols, so I don't see command line for each process.
I guess it is related to the fact, that it is no terminal attached when script is running under cron. But how to fix this?
5 REPLIES 5
Vitaly Karasik_1
Honored Contributor

Re: "top -c" doesn't work from under cron

export COLUMNS=127
Jeeshan
Honored Contributor

Re: "top -c" doesn't work from under cron

You can do like this

#export UNIX95=1;top -h -n5 -d1 -f

It'll run from crontab also.
a warrior never quits
Vitaly Karasik_1
Honored Contributor

Re: "top -c" doesn't work from under cron

[root@linux1 ~]# export UNIX95=1;top -h -n5 -d1 -f /tmp/top.out
top: procps version 3.2.3
usage: top -hv | -bcisS -d delay -n iterations [-u user | -U user] -p pid [,pid ...]
Jeeshan
Honored Contributor

Re: "top -c" doesn't work from under cron

youcan try like this

export UNIX95;top -d 1 -n 2
a warrior never quits
Stuart Browne
Honored Contributor

Re: "top -c" doesn't work from under cron

If it's just for one instance of the command, you can use set the variable in the same command, instead of exporting the variable, i.e.

UNIX95=1 top -d1 -n2

This sets the variable for that single command.
One long-haired git at your service...