I have a CRON task scheduled as followed:
30 18 * * 1-5 python python /home/pi/myscript.py
Why is it not executing?
it may be a permission issue, try running this in the console
chmod -R 777 /home/pi/myscript.py
The format of writing cron job is incorrect.
Correct entry for this is as following:
30 18 * * 1-5 "python /home/pi/myscript.py"
If you are using Python 3.x then change accordingly i.e.:
30 18 * * 1-5 "python3 /home/pi/myscript.py"
Related
I have configured cron job but it's not working.
I wanted to run the myfile.sh script for every 2 mint and below are my configuration in crontab.
# m h dom mon dow comman
2 * * * * /home/ubuntu/myfile.sh
myfile.sh is executable and contains below lines of code
#!/bin/bash
mysqldump -u[user] -p[password] --single-transaction --routines --triggers --all-databases > /home/ubuntu/backup_db10.sql
Is there anywhere we need to add configure anything?
You're running the script at two minutes past every hour. As in 1:02, 2:02 and so on.
You can change it to something like
*/2 * * * * /home/ubuntu/myfile.sh
to run it every two minutes.
A bit more info can be found here.
I have been researching this topic for the past two hours and can't find similar info. I am putting the last touch on a LED sign and I want it to run the script every x amount of minutes from raspberry to update the info going to the sign, lets just say every 10 minutes. I have tried everything with crontab -e and sudo crontab. my question is I have to run the file (mysign.py) from the directory in cd my_python and then from there I have to use the command sudo python3 mysign.py, it will not run with sudo python. I am wondering if this has anything to do with it?
here's some of what I have tried, along with the #reboot as well with nothing.
/10 * * * * /usr/bin/python mysign.py
/10 * * * * /usr/bin/python3 mysign.py
/10 * * * * /usr/bin/python /home/pi/my_python/mysign.py
/10 * * * * /home/pi/my_python/mysign.py
First of all, to execute on every 10th minute you need to use */10 ... not /10 ....
Second, entries from root's crontab execute as root, hence their home is not /home/pi - you actually need to specify the whole path for both the interpreter and the script:
*/10 * * * * /usr/bin/python3 /home/pi/my_python/mysign.py
Make sure you set it in the root's crontab (sudo crontab -e).
This, of course, assumes the location of your python3 interpreter and the script itself, if those paths are not correct - correct them before adding to crontab.
I want a user (tcff) to run two python scripts at 2am every morning.
I have correctly installed the following crontab for this user:
tcff#mymachine> crontab -l
0 2 * * * python /home/tcff/path/to/myscript1.py
0 2 * * * python /home/tcff/path/to/myscript2.py
The permissions for each script are:
-rwxr-xr-x 1 tcff tcff 5522 Sep 25 12:41 myscript1.py
-rwxr-xr-x 1 tcff tcff 5522 Sep 25 12:41 myscript2.py
When I call each script directly they work fine:
tcff#mymachine> python /home/tcff/path/to/myscript1.py
[Output as expected]
However they are not being run by cron at 2am each morning.
I can't work this out. I am sure I have the permissions correct etc?
Yes, indeed, the reason the scripts were not running is because I did not use the full path to the Python binary:
0 2 * * * /usr/bin/python /home/tcff/path/to/myscript2.py
This is needed because although the shell (bash) has /usr/bin on the PATH the process running cron does not.
First of all give full permission to script file.
chmod 777 script_name
Also trace the logs of crontab and see what is happening with cronjob here you can see all logs of crontab. May be there is any exception or error.
root#localhost:[~]: tail -f /var/log/cron
I want to make crontab where script occurs at different minutes for each hour like this
35 1,8,12,15,31 16,18,21 * * 0,1,2,3,4,5,6 python backup.py
I want script to run at 16hour and 31 minutes but it is giving me error bad hour
i want the cron occur at
1:35am , then 16:31, then 21:45
As there is not a pattern that can match the three times, it is not possible to schedule that just with one crontab expression. You will have to use three:
45 21 * * * python backup.py
31 16 * * * python backup.py
35 1 * * * python backup.py
Note also that python backup.py will probably not work. You have to define full path for both files and binaries:
35 1 * * * /usr/bin/python /your/dir/backup.py
Where /usr/bin/python or similar can be obtained with which python.
If the system which you are on has systemd, You can look into systemd timers(https://www.freedesktop.org/software/systemd/man/systemd.time.html). Then you might be able to achieve the randomness using the RandomizedDelaySec setting and an OnCalendar setting which will schedule the service to run every hour or interval you set plus will generate a RandomizedDelaySec at every run so that the interval is random.
At about 8:10 AM, I edited crontab tasks with "crontab -e", added a simple task which should run at 8:20 AM.
00 3 * * * sh /home/als6fd/bin/run1.sh
20 8 * * * sh echo "hello">>/home/als6fd/ggfan/1.txt
But it did not run at 8:20 AM. What may cause this problem?
If I call "/sbin/service crond reload", an error occurs.
problem fixed:
as current user does not have right to write to /home/als6fd/ggfan