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

Re: cronjobs and top not getting along

charles@lunarmedia.net wrote:
> I have a basic script running on my server that check for cpu utilization.
> If the number is over 70%, then it issues a page to let me know.
> The line in the script I use to gather the number for the cpu utilization
> is as follows:
> top | head -3 | tail -1 | cut -d " " -f 7 | cut -d % -f 1 > filename
> To test the script, I had the server page me with the current processor
> utilization:
> set usage = `cat filename`
> echo "The server is running at $usage percent" | page charles 123-4567 -
> >From the command line, everything works well, and I get a page
> saying the server is running at 2 percent. However, when this is ran as a
> cronjob, i receive the page and the variable is not included. Sure enough,
> when I cat filename, its empty. The server issues an email letting me know
> the error it encounters. I receive:
> top: ioctl() failed: Not a typewriter
> Is there a way around this. Frankly I am not certain what this error
> means, but I am sure that it has something to do with the fact that top
> refreshes itself. Top doesnt have a flag to disable the refresh, but there
> is one that allows the interval to be set. I am going to try to set the
> interval to a somewhat long length and see what happens.
> Any suggestions?
> thanks!
> Charles

That error is because top can't figure out what sort of terminal the
cron session is in, because it isn't in one.  So top gets confused
trying to figure out how to clear the screen and stuff.  The proper
approach would be to look at top's sources and figure out how it
computes the numbers.  It's somewhere in the /proc files, I'm just not
sure which one(s).

To unsubscribe, send email to majordomo@luci.org with
"unsubscribe luci-discuss" in the body.