9

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

wpercy
  • 9,636
  • 4
  • 33
  • 45
Ricardo Iglesias
  • 595
  • 2
  • 6
  • 16
  • 1
    on some Macs apparently `sysctl` is located in `/sbin/` instead of `/usr/sbin/`. Try adding `/sbin` to your PATH variable – wpercy Feb 16 '17 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? – Ricardo Iglesias Feb 16 '17 at 22:43
  • 2
    Well you don't want it to be `$HOME/sbin/` because `$HOME` is `/Users/` not the root directory `/`. So the short answer is yes, you're not adding PATH correctly. – wpercy Feb 16 '17 at 23:50
  • Thank you very much! This fixed it! – Ricardo Iglesias Feb 17 '17 at 23:16

1 Answers1

13

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

wpercy
  • 9,636
  • 4
  • 33
  • 45