1

I have a problem where I want to run (daily at 2pm) a Python code in my VM but the cronjob didn't work as expected.

Here is the code that i tried in crontab -e:

#1    
0 14 * * * /home/try/myf.py
#2
0 14 * * * /home/try/miniconda3/bin/python /home/try/myf.py
#3
0 14 * * * python /home/try/myf.py
#4
0 14 * * * /home/try/miniconda3/bin/python myf.py

All of this code didn't work for me. Can anyone explain or advice me on how to do the code? If possible, how can I check the log of this cronjob?

7
  • did you try "which python"? Commented Sep 29, 2021 at 6:38
  • yes i am. this is the output /home/try/miniconda3/bin/python Commented Sep 29, 2021 at 6:39
  • what's your user on server? are you root? Commented Sep 29, 2021 at 6:41
  • how can i know im a root or not? can u explain.... please... Commented Sep 29, 2021 at 6:46
  • if you are logged in on server, your user name should be user@your-server-ip in case of non root user otherwise it should be root@your-server-ip. DON'T PASTE YOUR IP HERE Commented Sep 29, 2021 at 6:56

2 Answers 2

1

Checklist:

  1. Check cron daemon running ? (ps aux | grep cron) or service cron status Service cron start or restart

  2. check if cron is working ? contab -e and add below line

            • ( /bin/date && /etc/echo "cronjob works" ) >> /tmp/file

    Then cat /tmp/file

There are other posts explaining checks and tests in detail, refer those

Sign up to request clarification or add additional context in comments.

Comments

0

#2 is correct, it works with miniconda3 on ubuntu instance.
Replace the code in myf.py with print('hello world') and try running ​ /home/try/miniconda3/bin/python /home/try/myf.py manually.
If it works, then it's a crontab issue. There's a great troubleshooting guide here.
If it doesn't work, then your miniconda installation is corrupted. Try reinstalling it following these instructions. Remember to close the terminal and re-open it after the installation, otherwise it won't work even if the installation has been successful.

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.