1
votes

I edited the crontab with -e option. Then I went to /etc/cron.d directory to create a file which would run the process. Again I edit the /etc/crontab file. But I couldn't made it run. I refered to this article from stackoverflow and did exactly same but I don't know why cron is not working for me ? here is how my crontab looks like -

# Edit this file to introduce tasks to be run by cron.
# 
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
# 
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').# 
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
# 
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
# 
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
# 
# For more information see the manual pages of crontab(5) and cron(8)
# 
# m h  dom mon dow   command
*/5 * * * * anikde /home/anikde/Documents/pythonProjects/python_scripts/* 
* * * * * anikde python /home/anikde/Documents/pythonProjects/python_scripts/test/write.py

I have set the 1st job to run after every 5 minutes and 2nd job after every one minute. But none of jobs are running automatically. While they actually run when I command the job to run first script as bash script and the second file as python script.

1
You don't need to manually create files in /etc/crontab. Just edit cron using crontab -e and relevant cron files will be updated. - KazikM
I did that, but the script is not running automatically. I am actually thinking to install cron again, will it be helpful? - Anik De
1. Check if your crontab schedule (first 5 colums in crontab entry). is correct. You can try different valus at crontab guru. Just replaca start with other proper values. - KazikM
2. Check if your command runs without a cron. Are you able to run it manually? - KazikM
3. Edit your post and include your exact crontab. Or include it in the comment. It hard to guess what can be wrong. - KazikM

1 Answers

0
votes

I assume you are trying to automatically run below script every 5 minutes:

/home/anikde/Documents/pythonProjects/python_scripts/test/write.py

First, determine the location of your Python executable, using which python command. In below examples I assume the returned path to be /usr/bin/python.

  1. If editing your own crontab (crontab -e) try this command:
*/5 * * * * /usr/bin/python /home/anikde/Documents/pythonProjects/python_scripts/test/write.py

If no user is specified, the job is run as the user that owns the crontab file, using his environment. But you can also try adding the username

*/5 * * * * anikde /usr/bin/python /home/anikde/Documents/pythonProjects/python_scripts/test/write.py

  1. If editing root crontab (sudo crontab -e)
*/5 * * * * anikde /usr/bin/python /home/anikde/Documents/pythonProjects/python_scripts/test/write.py