10

I have a python script, script.py, and am using cron to run this script periodically. The script runs as expected, but once the cron job finishes, I get the following error in /var/mail/[myusername]:

sh: sysctl Command Not Found

The following is the cron job:

0 14  * * * PATH=$PATH:/usr/sbin PYTHONPATH=/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ /usr/bin/python2.7 ~/.../script.py

I was told to include both PATH and PYTHONPATH in the task (as before, python wouldn't recognize several modules I had imported and had installed), so at this point, I'm not sure what the problem could be

4
  • 1
    on some Macs apparently sysctl is located in /sbin/ instead of /usr/sbin/. Try adding /sbin to your PATH variable
    – wpercy
    Commented Feb 16, 2017 at 22:05
  • In my ~/.bash_profile, my path variable is as follows: PATH=PATH="$HOME/sbin/:$PATH" export PATH And I'm still getting the error... Am I simply not adding PATH correctly? Commented Feb 16, 2017 at 22:43
  • 2
    Well you don't want it to be $HOME/sbin/ because $HOME is /Users/<username> not the root directory /. So the short answer is yes, you're not adding PATH correctly.
    – wpercy
    Commented Feb 16, 2017 at 23:50
  • Thank you very much! This fixed it! Commented Feb 17, 2017 at 23:16

1 Answer 1

15

On some Macs, sysctl is located in /sbin/ instead of /usr/sbin/. You should add /sbin to your PATH variable

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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