# How to run dietpi-update via cron job

**URL:** https://dietpi.com/forum/t/how-to-run-dietpi-update-via-cron-job/16829
**Category:** General Discussion
**Created:** [10 May 2023 11:00 UTC](https://dietpi.com/forum/t/how-to-run-dietpi-update-via-cron-job/16829 "2023-05-10T11:00:04Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![aw512](https://dietpi.com/forum/letter_avatar_proxy/v4/letter/a/ea5d25/32.png) [@aw512](https://dietpi.com/forum/u/aw512)
#### Post date: [10 May 2023 11:00 UTC](https://dietpi.com/forum/t/how-to-run-dietpi-update-via-cron-job/16829/1 "2023-05-10T11:00:04Z")

</div>

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,

```auto
#!/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?

---

<div class="post-metadata">

### Author: ![Jappe](https://dietpi.com/forum/user_avatar/dietpi.com/jappe/32/1788_2.png) [@Jappe](https://dietpi.com/forum/u/Jappe)
#### Post date: [10 May 2023 11:15 UTC](https://dietpi.com/forum/t/how-to-run-dietpi-update-via-cron-job/16829/2 "2023-05-10T11:15:19Z")

</div>

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`

---

<div class="post-metadata">

### Author: ![aw512](https://dietpi.com/forum/letter_avatar_proxy/v4/letter/a/ea5d25/32.png) [@aw512](https://dietpi.com/forum/u/aw512)
#### Post date: [10 May 2023 11:36 UTC](https://dietpi.com/forum/t/how-to-run-dietpi-update-via-cron-job/16829/3 "2023-05-10T11:36:37Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Jappe](https://dietpi.com/forum/user_avatar/dietpi.com/jappe/32/1788_2.png) [@Jappe](https://dietpi.com/forum/u/Jappe)
#### Post date: [10 May 2023 11:39 UTC](https://dietpi.com/forum/t/how-to-run-dietpi-update-via-cron-job/16829/4 "2023-05-10T11:39:08Z")

</div>

> # 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.

---

<div class="post-metadata">

### Author: ![Joulinar](https://dietpi.com/forum/user_avatar/dietpi.com/joulinar/32/57_2.png) [@Joulinar](https://dietpi.com/forum/u/Joulinar)
#### Post date: [10 May 2023 12:14 UTC](https://dietpi.com/forum/t/how-to-run-dietpi-update-via-cron-job/16829/5 "2023-05-10T12:14:04Z")

</div>

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](https://dietpi.com/forum/t/howto-call-dietpi-sync-1-without-user-interaction/15964/5) to avoid user input.

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

> <https://github.com/MichaIng/DietPi/blob/9e3f5d91edc7dc02784efdef1aaefe57b91cccfb/dietpi.txt#L200-L202>

---

<div class="post-metadata">

### Author: ![aw512](https://dietpi.com/forum/letter_avatar_proxy/v4/letter/a/ea5d25/32.png) [@aw512](https://dietpi.com/forum/u/aw512)
#### Post date: [10 May 2023 14:25 UTC](https://dietpi.com/forum/t/how-to-run-dietpi-update-via-cron-job/16829/6 "2023-05-10T14:25:15Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![WarHawk](https://dietpi.com/forum/user_avatar/dietpi.com/warhawk/32/21_2.png) [@WarHawk](https://dietpi.com/forum/u/WarHawk)
#### Post date: [11 May 2023 02:30 UTC](https://dietpi.com/forum/t/how-to-run-dietpi-update-via-cron-job/16829/7 "2023-05-11T02:30:35Z")

</div>

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”

---

<div class="post-metadata">

### Author: ![MichaIng](https://dietpi.com/forum/user_avatar/dietpi.com/michaing/32/7_2.png) [@MichaIng](https://dietpi.com/forum/u/MichaIng)
#### Post date: [13 May 2023 15:10 UTC](https://dietpi.com/forum/t/how-to-run-dietpi-update-via-cron-job/16829/8 "2023-05-13T15:10:20Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![WarHawk](https://dietpi.com/forum/user_avatar/dietpi.com/warhawk/32/21_2.png) [@WarHawk](https://dietpi.com/forum/u/WarHawk)
#### Post date: [15 May 2023 02:33 UTC](https://dietpi.com/forum/t/how-to-run-dietpi-update-via-cron-job/16829/9 "2023-05-15T02:33:58Z")

</div>

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
