10

I'm kinda new in Linux and I've just learned about scheduling tasks with cron. I have this small shell script that I've been using manually till now:

sudo apt-get check && sudo apt-get update && sudo apt-get upgrade && sudo apt-get autoremove && sudo apt-get autoclean

Now I want to schedule it using cron so I won't manually do it every day, but it seems I can not do so. I suppose it is because it requires my sudo password in order to proceed? Is there any way I can make this work without auto-accepting the upgrades and so on?

Alexandru Banu
  • 105
  • 1
  • 2
  • 4

1 Answers1

14

It's a better idea to use "unattended-upgrades" instead.

Its purpose is to keep the computer current with the latest security (and other) updates automatically. [1]

To install:

sudo apt install unattended-upgrades

Read more about how to get it work: here.


To address your question, you can edit /etc/crontab file and run your commands using root user without the need of using sudo in your own "crontab" file.

nano /etc/crontab

and add a line like:

45 21 * * * root apt-get update > /home/ravexina/out.log

which runs apt-get update using root user at "21:45" every night and logs the output to /home/ravexina/out.log.

Ravexina
  • 57,256