[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: shell scripting question



On Wed, May 19, 2004 at 08:11:35AM -0500, Michael Martinell wrote:
} Hopefully somebody here has perhaps seen this oddity and can provide some
} insight into the cause.
} 
} I have a very simple shell script as follows:
} mail:~/scripts# more topcheck
} #!/bin/bash
} date > /usr/local/apache/htdocs/topout.txt
} echo "\c" ; top -n 1 >> /usr/local/apache/htdocs/topout.txt
} 
} I have also tried just:  top -n 1 >> /usr/local/apache/htdocs/topout.txt
} Both top commands do the same thing.
} 
} I then have this scheduled in cron to run every 5 minutes.
} 
} If I run this from the command line I get a nice report.  When I run it in
} cron all I get is the date.
} 
} Does anybody know why this would happen like this?

Do you have local mail delivery set up properly? If so, the output from
any cron command would be mailed to you and you would see the following:

TERM environment variable not set.

If you set TERM in your script you will get the following output:

        top: failed tty get

It appears that top will not tolerate not being attached to a tty, but
you can actually give it the -b flag and you will get the results you
are looking for. Incidentally, there is no reason to make it a bash
script rather than vanilla sh, and you can simplify the script by using
exec:

#!/bin/sh
TERM=vt100
export TERM
exec > /usr/local/apache/htdocs/topout.txt
date
top -b -n 1

--Greg



Reply to: