[rrd-users] Re: problems with update & cron?

Dave Plonka plonka at doit.wisc.edu
Thu Mar 23 05:23:17 MET 2000

On Thu, Mar 23, 2000 at 10:29:22AM +1100, Matthews, Kathy (New) wrote:
> I'm a bit of an rrdtool newbie, but what I'm trying to do is get the cpu
> usage of our server.  I seem to be able to create the .rrd file ok:
> RRDs::create ($rrd, "-b",$start,"--step",300,
>               "DS:user:GAUGE:600:U:U",
>               "DS:system:GAUGE:600:U:U",
>               "DS:idle:GAUGE:600:U:U",
>               "RRA:AVERAGE:0.5:1:24");
> and I'm using snmp to get user, system and idle times.
> My update looks like this:
> RRDs::update ("$rrd", "$t:$cpuuser:$cpusystem:$cpuidle");
> the problem is when I update I get NaN if it is run from cron (Solaris 2.6),
> but if I manually update it gets there ok.
> What am I doing wrong?


>From the code fragments, it looks like you're not checking return
statuses, nor printing any diagnostic/error messages, however this
doesn't sound like an RRD problem, per se.

Instead, it sounds like a typical problem with your script's process
environment missing something (such as an environment variable) when it
runs in cron that your processes usually have when you log in (such as
might be set in your ".profile").

Perhaps your snmp queries need an environment variable, for instance.

An easy way to ensure that your cron jobs get the same environment as
when you are logged in is to cause the cron job to run a login shell.
Here's the one liner that I use to "wrap" most crontab entries:

   0 * * * * /usr/bin/perl -e '$_ = (getpwnam($ENV{"LOGNAME"}))[8] || die "getpwnam: $!"; m:^(.*/(\w+))$: || die "match failed"; exec {$1} "-" . $2, "-c", "YOUR_COMMAND_HERE"; die "exec: $!"'

It first launches perl, which determines the shell you use as your
login shell, then invokes it as a login shell (by causing argv[0] to
begin with "-") and asks it to run the command you wish.

One caveat when using this method is that you should write your
".profile" and shell "rc" files to not produce errors when not running
on a tty.  For instance, if you have stty(1) commands in your
".profile", you'll have to test something like this:

   if [ -t 0 ]
   then # stdin is a tty - we're not running in cron
      stty erase ^H

Other equivalent tests are:

   if test -t 0
   then # ...


   if tty -s
   then # ...

I mentioned ".profile" as an example... if for some strange reason your
not using sh, ksh or a work-alike and instead are using a csh derived
shell, the syntax will differ in your ".login".


plonka at doit.wisc.edu  http://net.doit.wisc.edu/~plonka  ARS:N9HZF  Madison, WI

Unsubscribe mailto:rrd-users-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-users-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/rrd-users

More information about the rrd-users mailing list