How to run dietpi-update via cron job

How can I run dietpi-update non interactively via a cron job?

I have created a scrip file in /etc/cron.weekly that contains the following,

#!/bin/bash

dietpi-update
sudo apt-get update && sudo apt-get upgrade -y

I get an error saying dietpi-update: command not found . If the command were to run I suspect it would not update the system due to diepi-update being interactive. How can I run it non-interactively?

You need to use the full path inside cron: /boot/dietpi/dietpi-update
Same for apt-get I think: /usr/bin/apt-get update && /usr/bin/apt-get upgrade

Thanks, adding the full path worked.
I can’t test if diepi-update will run non-interactively since I’m on the latest version. Do I need to add something so that it automatically selects to update the system without user input?

Usage:

# - dietpi-update	= Check for DietPi update and if available open interactive menu
#			  Else, if CONFIG_CHECK_APT_UPDATES=[12] is set, check for APT updates and store results to /run/dietpi/.apt_updates to be used by DietPi-Banner
# - dietpi-update 1	= Check for DietPi update and in case apply noninteractively
#			  Else, if CONFIG_CHECK_APT_UPDATES=2 is set, check for and apply APT updates noninteractively
# - dietpi-update 2	= Check for DietPi update and in case store result to /run/dietpi/.update_available to be used by DietPi-Banner
#			  Else, if CONFIG_CHECK_APT_UPDATES=[12] is set, check for APT updates and store results to /run/dietpi/.apt_updates to be used by DietPi-Banner
# - dietpi-update -1	= Like "1" but internally reduce subversion by 1 to reapply the last update, e.g. to apply latest dev branch changes
#////////////////////////////////////

So just add a 1 to the command.

We don’t offer such a functionality by design as we like to get user aware on the update and watch the output. Sometimes there are important in formation changes done or needed software reinstall.

For interactive execution, you might need to export G_INTERACTIVE=0 [howto] call dietpi-sync 1 without user interaction - #5 by MichaIng to avoid user input.

For apt package updates, we offer a build-in functionality. No user own script or cron would be needed.

I forgot how sometimes dietpi-update prompts to install patches, etc.
I will remove the cron job and go with the option you provided of setting dietpi.txt to CONFIG_CHECK_APT_UPDATES=2

Thanks for the help.

you could also create a alias in /home/user directory/.bashrc then do a sudo update and it would auto run the commands

alias update=“sudo apt-get update && sudo apt-get upgrade -y”
I also put a quick list using ll two L’s for listing directories as an alias

alias ll=“ls -lah --color=default”

That would run it on every login and every (interactive) subshell in foreground, blocking the console until done, which would be quite annoying for me and implies unnecessarily much disk I/O. I think the daily (nightly scheduled) builtin feature should be fine for most users and logs can be reviewed every once in a while.

It would only run if you typed the word “update” in the shell, then it would ask for sudo password to run it
but I get what you are saying