0

what will happen if I put my update and upgrade command on /etc/rc.local??

after reading some forums and all I understand that we can use crontab and so on. But what will happen if I do it in this way.

rc.local

2
  • 1
    Try it and see. You don't need sudo in rc.local, when run at boot it is executed with root privileges.
    – goldilocks
    Mar 16, 2021 at 13:42
  • Don't do that. Use apt automated updates. wiki.debian.org/UnattendedUpgrades
    – Dougie
    Mar 16, 2021 at 17:40

3 Answers 3

3

rc.local gives you no guarantees that the network is available, so your command will likely fail without doing what you expect it to do.

There is a proper way to get unattended upgrades working, which is configured in /etc/apt and activated by

sudo dpkg-reconfigure --priority=low unattended-upgrades

Note that automatic updates work best when you also have automatic backups in place.

2

My answer is offered in the spirit of KISS, and is this:

Don't try to automate your updates & upgrades - not in rc.local, not in cron, and not even in systemd. Why? As the bumper sticker says, "Shit Happens".

Also - there are times when a reboot is required to load a new kernel - not doing so can cause strange and errant behavior with some apps. Unfortunately, the system will not tell you when a kernel update was made, and so you either guess when it's needed, or you reboot after each update && upgrade. Some of the Debian distros have a reboot-required flag, but last I checked the Raspbian crowd hasn't ported this.

Automating update && upgrade is inviting trouble - trouble that may take much more time and effort to unwind than 100 manual update && upgrade.

If you want a notification or reminder to update && upgrade at a certain date & time, this can be arranged in numerous ways. If you want an event-based reminder, consider setting up apt-listchanges to send you a daily email (or redirect it to your /etc/motd).

1

Do NOT put ANYTHING in rc.local - especially anything which is dependent on networking.

Automatic update is a bad idea as it sometimes prompts for user input.

If you REALLY need this for some remote application (I still think it is a bad idea) install unattended-upgrades.

1
  • AFAIK apt-get is smart enough not to ask anything when there's no input terminal. Granted, you'd still need to specify -y, otherwise it will likely just abort on the first question instead of assuming the answer is "Yes". Mar 17, 2021 at 9:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.