Daily Crontab Jobs

I was Looking for some daily commands to be executed on my server ubuntu 20.04. Please help me

Commands to be daily executed on night 11:25pm

sudo service apache2 restart
sudo apt update
sudo apt upgrade -y
sudo apt autoremove -y

sudo reboot

Please help me. Thanks in advance

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Site Moderator
Site Moderator badge
February 27, 2021
Accepted Answer

Hi @kaustubhk24,

You correctly mentioned crontab. You can configure this as a script to run every day at 11:25pm.

Let’s first start with creatng the script. SSH to your droplet and start executing the following commands

touch ~/updateScript

The above will create the file for you. Now it’s time to edit it.

nano ~/updateScript

Inside of it, you can type in the following


sudo service apache2 restart
sudo apt update
sudo apt upgrade -y
sudo apt autoremove -y
sudo reboot

Save the file and exit. Now time to make sure your script is executable

sudo chmod +x ~/updateScript

Now the last bit, add it to your crontab. To do that, type in

crontab -e

WHen the file opens at the bottom of it, add the following line

15 23 * * * bash ~/updateScript

Save the file and exit from it. To make sure you’ve added the cron, type in

crontab -l 

You should see the command you added at the bottom.

Regards, KFSys

A word of caution: there are times when going through the update/upgrade process requires user input beyond the -y flag. There are times an upgrade will change a config file that would wipe out any customizations you have previously set up, or change the location of a file, etc. This has the potential to make the cron script hang or fail every day until you check on it again.

My personal recommendation is to run the update/upgrade as a manual process.

For a suggestion on a script to run daily might be to have server logs emailed to you.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel