Schedule apt-get script using cron
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
.