2

Directory: path/to/test

tree:

.
├── Pipfile
├── test.py
├── test.sh
└── test.txt

test.py:

#!/usr/bin/env python3

import datetime

with open("/path/to/test/test.txt", "a") as f:
    f.write(f"{datetime.datetime.now()}\n")

test.sh:

#!/bin/zsh

pipenv run python /Users/ayubkeshtmand/Downloads/test/test.py

crontab -l:

SHELL=/bin/zsh
PATH=/Library/Frameworks/Python.framework/Versions/3.10/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/bin/python3:/Library/Frameworks/Python.framework/Versions/3.10/bin:/opt/homebrew/bin:/opt/homebrew/sbin

* * * * * env > /tmp/env.output                   # works
* * * * * touch /path/to/anothertest.txt          # works
* * * * * python /path/to/test/test.py            # doesn't work
* * * * * python3 /path/to/test/test.py           # doesn't work
* * * * * pipenv run python /path/to/test/test.py # doesn't work
* * * * * zsh /path/to/test/test.sh               # doesn't work
* * * * * /Library/Frameworks/Python.framework/Versions/3.10/bin/python3 /path/to/test/test.py # doesn't work
* * * * * bash -l -c "python /path/to/test.py"    # doesn't work
* * * * * bash -l -c "pipenv run python /path/to/test.py"    # doesn't work

/tmp/env.output:

SHELL=/bin/zsh
PATH=/Library/Frameworks/Python.framework/Versions/3.10/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/bin/python3:/Library/Frameworks/Python.framework/Versions/3.10/bin:/opt/homebrew/bin:/opt/homebrew/sbin
LOGNAME=myusername
USER=myusername
HOME=/path/to
SHLVL=0
PWD=/path/to
OLDPWD=/path/to
_=/usr/bin/env

env in regular terminal:

USER=myusername
MallocNanoZone=0
__CFBundleIdentifier=com.microsoft.VSCode
COMMAND_MODE=unix2003
LOGNAME=myusername
PATH=/Library/Frameworks/Python.framework/Versions/3.10/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/bin/python3:/Library/Frameworks/Python.framework/Versions/3.10/bin:/opt/homebrew/bin:/opt/homebrew/sbin
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.RyAiUT08FA/Listeners
SHELL=/bin/zsh
HOME=/path/to
__CF_USER_TEXT_ENCODING=0x1F6:0:2
TMPDIR=/var/folders/64/wd951s6x3pz3ytpq1wjz5n180000gp/T/
XPC_SERVICE_NAME=0
XPC_FLAGS=0x0
ORIGINAL_XDG_CURRENT_DESKTOP=undefined
SHLVL=1
PWD=/path/to
OLDPWD=/path/to
HOMEBREW_PREFIX=/opt/homebrew
HOMEBREW_CELLAR=/opt/homebrew/Cellar
HOMEBREW_REPOSITORY=/opt/homebrew
MANPATH=/opt/homebrew/share/man:/usr/share/man:/usr/local/share/man:/opt/homebrew/share/man:
INFOPATH=/opt/homebrew/share/info:/opt/homebrew/share/info:
GITHUB_TOKEN=fwlkehjgowih4t089240btonglkwenkjbalfihoi283
TERM_PROGRAM=vscode
TERM_PROGRAM_VERSION=1.74.1
LANG=en_GB.UTF-8
COLORTERM=truecolor
GIT_ASKPASS=/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/git/dist/askpass.sh
VSCODE_GIT_ASKPASS_NODE=/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper.app/Contents/MacOS/Code Helper
VSCODE_GIT_ASKPASS_EXTRA_ARGS=--ms-enable-electron-run-as-node
VSCODE_GIT_ASKPASS_MAIN=/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/git/dist/askpass-main.js
VSCODE_GIT_IPC_HANDLE=/var/folders/64/gowiehg92834hbgobwkgjegp/T/vscode-git-45fnwiuheg284.sock
VSCODE_INJECTION=1
ZDOTDIR=/path/to
USER_ZDOTDIR=/path/to
TERM=xterm-256color
PS1=%n@%m %1~ %# 
_=/usr/bin/env

No logs in /var/logs and no mail outputted...searched everywhere online nothing works!

AK91
  • 671
  • 2
  • 13
  • 35
  • 2
    maybe trying running a quick script to print hello world with `* * * * * /Library/Frameworks/Python.framework/Versions/3.10/bin/python3 /path/to/test/helloworld.py >> ~/helloworld.out 2>&1`. If successful this should write to the outputfile in your home directory, so you can test if python is working – bn_ln Dec 16 '22 at 12:27
  • Random observation: Cron, by default, tries to e-mail any output from the command, to the user. Hardly any Mac has its e-mail subsystem set up for anything other than local delivery, meaning that those mails end up in a place that a normal user never checks. Try running `mail` from the command line and see if there’s anything there for you. (By the way, you have tagged "linux", but /Library/Frameworks seems to indicate you’re on a Mac...) – Ture Pålsson Dec 16 '22 at 12:51
  • @bn_ln output saying `/Library/Frameworks/Python.framework/Versions/3.10/bin/python3: can't open file '/path/to/test/helloworld.py': [Errno 1] Operation not permitted` tried a `chmod +x /path/to` but nothing? – AK91 Dec 16 '22 at 14:44
  • Dockerising the script works, only problem is that computer needs to stay on for it to run... – AK91 Dec 16 '22 at 15:27
  • @AK91 your test script `helloworld.py` only needs read permission, so use `chmod +r helloworld.py` instead of `+x` – bn_ln Dec 17 '22 at 23:12

0 Answers0