Crontab doesnt run python script
Your script is executed by Cron and everything works as it is expected. Just Cron isn't designed to output anything into a terminal. So, IMO, the correct question here should be something like: Where the standard output goes within Cron?
Unless it is redirected (>
, >>
) or piped (|
) to another program, everything that usually will be outputted to the STDOUT (if you are execute a command in the command-line), including all error messages, will be sent to the local mailbox of the user that runs the Cronjob. To send/receive these emails you should apply a minimal configuration as it is described here: How do I set Cron to send emails?
Most of the suggestions in the proposed duplication explain how to redirect the output of a Cronjob to TTY or terminal window, but to get the output there you should be login (in that TTY or terminal window) in advance. Here are few additional examples:
Crontab and program that should be executed into a terminal window
How to launch any GUI related application from Crontab in Ubuntu
In addition, in this case:
-
cd /home/
is not needed because your script doesn't write anything there, and the script is called by its full path. -
/usr/bin/python
is not neede, because you tell the system that is Python script by the shebang#!/usr/bin/env python
. But in this case the file should have executable permissions:chmod +x /home/hello.py
.
Related videos on Youtube
Artem Andreev
Updated on September 18, 2022Comments
-
Artem Andreev over 1 year
I have the following issue: my 'hello world' python script can't be run by crontab.
If I set crontab instruction like this:
* * * * * cd /home/ && /usr/bin/python /home/hello.py
Text doesn't appear in terminal.
But if I do:
* * * * * cd /home/ && /usr/bin/python /home/hello.py >> /home/log.txt
Ubuntu appends 'hello world' text to log.txt
here is my script:
#!/usr/bin/env python print('Hello World!')
What am I doing wrong?
P.S. already read this topic Why crontab scripts are not working?
-
Ali Razmdideh about 6 yearsYou should set terminal and display. Please read this answer askubuntu.com/a/309892/550618
-
Ali Razmdideh about 6 yearsPossible duplicate of Getting output from a cron job on the terminal
-
-
pa4080 about 6 yearsThe user should be login that tty first. Otherwise we go back to the question - where goes STDOUT within Cron? :)