Search code examples
python-3.xmacoscronnightwatch

command works right in python subprocess when run on terminal but failed when execute in crontab


I am trying to launch a nightwatch tests daily from crontab. Everything works fine when I launch my python script on macOS terminal, but once I launch cron job by calling my python script . Error below occurred :

"env: node: No such file or directory"

I tried to set Below is the command I try to run from python subprocess:

cmd_run =["/usr/local/bin/yarn test /Users/mytest/path/ --tag dbg"]
child_env = os.environ.copy() // inherit shell env setting ? 

with open(full_log, 'w') as fd:
        process=subprocess.Popen(cmd_run, stdout=fd, stderr=fd, shell=True, env=child_env)

The actual command I need to run is :

E2E_BASEHOST=https://<myhost> E2E_ENV=bk E2E_TESTS_DIRECTORY=./bk/tests **node**  node_modules/nightwatch/bin/runner.js -c ./node_modules/@bk/e2e-testing-configuration/src/nightwatch.conf.js
--group affiliates/bookings2/tests/src/app/ --tag bsb --retries 2

I guess it is because subprocess cannot find "node" I run "which node" on my terminal It can be find here :

/usr/local/bin/node

So what is the thing I am missing here ?


Solution

  • You can put this in your crontab :

    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin