I'm on FreeBSD11. I have a shell script code as cron job that check the zfs pool status and save it in a sqlite database. when I run it from terminal, it work properly but in crontab it does't work. The crontab:

#minute hour    mday    month   wday    who     command

*/1    *     *    *   *   root  /usr/local/etc/myjob/pool/pool.sh

my script is:

pool=$(/sbin/zpool status | grep pool |awk '{print $2}')
for i in $pool
    status=$(/sbin/zpool status ${i} |grep state|awk '{print $2}')

    echo 'update mytbl set status =  '\'''$status''\'';'|sqlite3  /usr/local/var/db/myproject/myDataBase.db


Can you help me figure out the mistake?

  • Redirect the output to a file and see what error messages it might be giving you. (Append >/tmp/cronpool.log 2>&1, for example.) – roaima Mar 15 '17 at 7:45
  • Please confirm how you added this to a crontab, and if you did it by editing a file please provide its name and location. – roaima Mar 15 '17 at 7:46
  • Does your script depend on the current directory it's run in? That's a common gotcha with cronjobs. Can you post your script in your question, it's likely that the problem lies in it. Is it possible that your script take more than 1 minute to run? Maybe the problem is that the script runs concurrently with itself. Apart from that, note that */1 is redundant and that you can write *. – lgeorget Mar 15 '17 at 7:46
  • Do you use environment variable, which might not be defined? – Michael Vehrs Mar 15 '17 at 7:48
  • I added the script. – F.M Mar 15 '17 at 8:00

Specify the full path of sqlite in your script.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.