Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

General discussion

Running top command in cron

Sep 19, 2005 2:43AM PDT

I'm trying to run the top command using the crontab scheduler. top just doesn't seem to run in cron. It's like it just skips the command. The same thing happens with uptime as well. Here is my script essentially:

#!/bin/bash -l
LOG_FILE=/log/log.file

top -b -n 1 > $LOG_FILE

The top command just doesn't give any output. I can run top just fine from the command line. I'm certain it's some environment variable that I need to set up in cron, but I don't know what it is. Any help would be greatly appreciated.

My OS is SUSE 9.

Thanks

Discussion is locked

- Collapse -
Reply to: Running top command in cron
Sep 19, 2005 7:03AM PDT

Are you sure that you have permission to write into the log file? Do you have the execute permission set for the script? You do relize that each time that it runs it replaces the log file with the current data.

- Collapse -
Reply to: Running top command in cron
Sep 19, 2005 8:12AM PDT

Yeah, I have permissions to write to the log file. The script is doing a little more than just writing the top command to a log. It also echoes the date to the log file and some other info, so I know I can write to it. And I'm actually appending to the log file instead of overwriting it. So I guess it should be:
top -b -n 1 >> $LOG_FILE

- Collapse -
top & cron
Oct 4, 2005 10:41PM PDT

include export TERM=xterm in your shell script