0

I simply want a script that runs a few update commands. I want them to happen at 3am every day.

I cannot figure out why they don't work. I added this like to crontab -e

0 3 * * * root /etc/cron.custom/update

The script in the update file is

#!/bin/bash
# if not root, run as root
if (( $EUID != 0 )); then
    sudo /home/jb/bash/update.sh
    exit
fi
apt-get update
dietpi-update
apt-get -y upgrade
apt-get -y dist-upgrade
apt-get clean
apt-get -y autoremove
reboot

I don't know how to make scripts so I found that off the internet. It is surprisingly hard to find any answers on how to edit anything to do with cron.

Unattended upgrades doesn't upgrade everything so before anyone recommends it I tried it already and it missed heaps constantly.

In short how do I auto update and upgrade my device?

Running Debian (DietPi).

2
  • 3
    Have you checked the local mailbox on that machine? cron sends the result of the command there. Mar 16, 2017 at 5:28
  • 4
    put your script into /etc/cron.daily. that's all, no need to edit any crontab files. Mar 16, 2017 at 6:19

2 Answers 2

0

Create the folders needed then nano and crontab. Done.

sudo nano /home/jb/scripts/update

#!/bin/bash
apt-get update ; apt-get -y upgrade ; apt-get -y dist-upgrade ; apt-get clean ; apt-get -y autoremove ; reboot

sudo crontab -e

0 3 * * * sudo bash /home/jb/scripts/update
-1

(I can fully confirm your allegations from my own experience. Just recently I tried to make some cronjobs work on Raspbian and none of them worked in any standard way of setting up crontab.)

Now here is what you have to do, just copy&paste most of this:

mkdir /home/jb/scripts
sudo cp /etc/cron.custom/update /home/jb/scripts/
sudo crontab -e

Add the following to the now opened crontab: 0 3 * * * sudo bash /home/jb/scripts/update

Exit crontab.

(YES, the sudo HAS to be added, even though the crontab -e is already in sudo mode...)

Also change the update file to:

#!/bin/bash
apt-get update dietpi-update apt-get -y upgrade apt-get -y dist-upgrade apt-get clean apt-get -y autoremove reboot
2
  • It's much better to add plain standalone scripts to /etc/cron.daily: they run with root privileges and you needn't muck with defining a schedule either. Also, you miss the command separators from the script. Mar 17, 2017 at 9:52
  • As I made clear in my answer, usual ways dpn't work on that system.
    – Akito
    Mar 17, 2017 at 9:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .