1

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:

 #
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/etc/myjob/pool
#
#minute hour    mday    month   wday    who     command
#

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

my script is:

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


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

done

Can you help me figure out the mistake?

5
  • Redirect the output to a file and see what error messages it might be giving you. (Append >/tmp/cronpool.log 2>&1, for example.) Commented Mar 15, 2017 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. Commented Mar 15, 2017 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
    Commented Mar 15, 2017 at 7:46
  • Do you use environment variable, which might not be defined? Commented Mar 15, 2017 at 7:48
  • I added the script.
    – F.M
    Commented Mar 15, 2017 at 8:00

1 Answer 1

2

Specify the full path of sqlite in your script.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .