I’m executing the following commands in a perl script.
#!/usr/bin/perl
my $MPSTAT="/usr/bin/mpstat";
my $GREP="/bin/grep";
my $FREE = "/usr/bin/free";
my $AWK = "/bin/awk";
my $cpu = `$MPSTAT | $GREP all | $AWK '{print (100 - \$12)}'`;
print "CPU is $cpu";
When I run this perl script manually it’s getting executed properly and providing the proper CPU Usage in % (100 – Idle CPU).
But when I execute it as a cronjob it always prints 100 & it appears that $12 of awk is getting the value of 0. Any pointers on why it’s behaving differently in cron would be helpful.
The main differences between running as a child of cron are:
The second part often means that programs might output in a different language or number format due to the values of the
LANGandLC_*environment variables which might be set for the normal user but not when run under cron (or vice versa).