Delay execution of crontab until #reboot was executed - cron

Every time I start my raspberry pi, I want to update and upgrade it.
No other cronjob should be run before this is finished.
My crontab looks like this now
#reboot sudo apt-get update && sudo apt-get upgrade -y
*/9 * * * * (python script1.py) &
*/4 * * * * (python script2.py) &
How do I make script1 and script2 wait?

Related

Running node script with crontab

I'm trying to run a node script with crontab. I've tried first doing things like
* * * * * echo test > test.txt
to be sure crontab works (I'm trying to make the command work and then I'll change the crontab to something different so it doesn't run every minute).
The crontab above works. The thing is, when I try to use node, it doesn't run with the crontab. Running which node I get /usr/bin/node Here are the things I've tried.
Thanks!
* * * * * cd /path/to/script && node script.js
* * * * * cd /path/to/project && npm start (runs npx tsc && node build/script.js)
* * * * * cd /path/to/script && node script.js > test.txt (file is generated empty, even though, script has console.log)
* * * * * node /path/to/script/script.js
* * * * * echo test > test.txt && node /path/to/script/script.js (file gets generated)
Also I've tried all of the above replacing node by /usr/bin/node.
If I run any of these commands manually, it executes the program.
After going over a long time and testing a lot of stuff, I realized the issue was doing sudo crontab -e to set the crontab. I fixed it after running instead
sudo crontab -u username -e

Pi Cron Job Fails to Run

Hoping someone can help with a crontab issue I am having on the pi.
I have a program, rf24_receiver.py, that resides in the /home/pi directory. When run from terminal, it requires sudo to run. So with this command on terminal,
sudo python3 rf24_receiver.py, the program executes perfectly.
However, I need to run it on a schedule, so I tried the following without success.
crontab -e
*/30 * * * * sudo python3 /home/pi/rf24_receiver.py >> /home/pi/rf24_receiver.py.log 2>&1
Then I tried this
*/30 * * * * python3 /home/pi/rf24_receiver.py >> /home/pi/rf24_receiver.py.log 2>&1
Then I tried this
sudo crontab -e
*/30 * * * * sudo python3 /home/pi/rf24_receiver.py >> /home/pi/rf24_receiver.py.log 2>&1
Then I tried this
*/30 * * * * python3 /home/pi/rf24_receiver.py >> /home/pi/rf24_receiver.py.log 2>&1
No success with any of the above. I hope this is the right place to post this.
Any help would be appreciated.
Thank you
Sorry to bother the forum with this question. I am not sure why I got this command to work under sudo crontab -e:
*/29 */1 * * * sudo python3 /home/pi/rf24_receiverR3.py >> /home/pi/rf24_receiverR3.py.log 2>&1
I did a reboot and it seemed to work after that.

How do I execute cron service in linux?

I am trying to run a Python code every minute in Linux but at loss to configure cron service. Following is what I added after running 'crontab -e' but nothing is happening.
* * * * * cd /home/kali && /usr/bin/python3.8 /home/kali/time.py
time.py contains simple code to show current time.
from datetime import datetime
print(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
Any suggestions?
Firstly you need to add it to crontab,try:
sudo nano /etc/crontab
and after that you can put your service:
* * * * * cd /home/kali && /usr/bin/python3.8 /home/kali/time.py
Check it again 'sudo crontab -e'
you should run your code with python3. i dont understand why you use cd command, so i omit that.
This is the way you can run your python code in cron:
* * * * * python3 /home/kali/time.py
Note: Check if you have permission to execute .py file.

I can't get crontab to run, sudo python3 to run script an issue?

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.

How to make linux to reboot every day?

I tried to use cron but I don't see it reboots - no one program restarts.
I wrote to my crontab -e
48 8 * * * sudo reboot
I tried to make it reboot every day at 8:48. Why it doesn't work?
Sudo? Try without sudo in root crontab.
Use sudo crontab -e and include "/sbin/" on your command "reboot.
48 8 * * * /sbin/reboot

Resources