I want a daily backup, update and reboot on my raspberry pi (Raspbian GNU/Linux 9 (stretch) using a cron job.
So with root I use crontab -e and set the following jobs:
30 3 * * * /mnt/usb/backup/scripts/backup_daily.sh
00 3 * * * apt-get update
To update and backup a couple folders every day between 3am and 3:30.
Now after this I want to reboot the system. I know I can do something like
0 4 * * * reboot now
But I'm afraid that maybe my backup is still doing it's thing. Is there a way I can add a reboot job after my script has successfully finished?
At the last line of the backup_daily.sh put the reboot command.
and don't do it from cron.
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 am running SUSE Linux as a non-root user (getting root access also will not be a possibility). I would like to have a .sh script I created be run daily.
My crontab looks like:
0 0 * * * * /path/to/file.sh
I also have a line return after this as per many troubleshooting suggestions. My script deletes files older than 14 days. I also added a means to log output to check whether the script runs.
However, the job does not run automatically. I also am not able to check /var/log/messages for any notifications on whether cron can run or not.
What am I doing wrong? How can I check if cron itself is running/can run for my user? Do I have to supply cron with any paths or environment variables?
The correct approach to run your cron every midnight is:
00 00 * * * /bin/bash path/to/your/script.sh >> /path/to/log/file.log
Basically, this is my crontab
0 */3 * * * sleep 70 && touch /etc/banner && reboot
10 */6 * * * /root/updater
The first does a reboot and the second does an update. I want to check for updates every six hours, but reboot every 3 hours. I want them both to be independent.
I gave an offset of 10 minutes to the update script thinking it might compensate for the reboot time. Reboot time is about a minute on my Linux board.
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
I'm using a Raspberry Pi for a status display, but for whatever reason it gets incredabbly sluggish after a day or so of running so I wanted to reboot it every day so I setup a cron job to do that every morning at 8:50. But, it doesn't seem to be working. Is there anything special about using cron to do a reboot?
This is my crontab for the root user:
# m h dom mon dow command
50 8 * * * shutdown now -r >> /var/log/cron.log
0,30 * * * * date >> /var/log/cron.log
The second line works just fine, but I can't seem to get the restart command to work. It doesn't even output anything to the log.
Try using the fully specified path to shutdown. date may be in the PATH in roots cron environment, /sbin may not be looked up.
You need to edit the root user crontab
sudo crontab -e
then..
50 8 * * * reboot
Save and exit.