Here's a snippet of a bash script I'm writing to log CPU loads:
#!/bin/bash
# ... irrelevant nonsense ...
cmd1="/usr/bin/mpstat -P ALL | egrep '(AM|PM)([[:space:]]+)(0)' | tr -s ' ' | cut -d' ' -f4"
ldsys="$(echo $cmd1 | /bin/sh)"
# ... irrelevant nonsense ...
$ldsys
is set properly when the script is executed conventionally from the console. It's golden. Here's the issue: when executed with crontab, $ldsys
is empty.
I've been trying millions of things for the last three hours to try to get this thing work... but I can't find anything. Does anyone have any ideas?
Notes:
/usr/bin/mpstat
can be executed by cron. I tested by adding a bogus task to fire every minute:/usr/bin/mpstat -P ALL >> somefile
and checking the output. It works.egrep
,tr
, andcut
all function fine under cron.I'm thinking it really has to do with the eval assignment convention... but I don't know why that would be an issue considering it's a relatively-fundamental construct...After trying Adam's suggestion, I now have no idea what to think...
Edit: stripped out eval
usage... still no dice.