0

I add this line to crontab -e

* * * * * /root/Desktop/New.py

The New.py code is simple creating a text file here is the code of it

#!/usr/bin/python
f= open("test.txt",'w')
f.write("test")
f.close()

when I test executing the code using the shell it works correctly and when I tested the Cron using echo to a text file the Cron also works correctly, and I set the python file permission to executable, But still it doesn't work

2 Answers 2

2

I think whats happening is the cwd is not what you are expecting it to be. Try an explicit cd to a directory where you want the file to be created

SHELL=/bin/bash
* * * * * cd /root/Desktop; /root/Desktop/New.py
Sign up to request clarification or add additional context in comments.

2 Comments

I changed the New.py file to f= open("/root/Desktop/test.txt",'w') and it is working as expected thanks
Glad I was able to help.
0

try this

* * * * * python /root/Desktop/New.py

or this

* * * * * export DISPLAY=:0; python /root/Desktop/New.py

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.