-1

I am running several Raspberry Pi 4 on Bookworm. On these, I have a bash file as follows:

sudo apt -y update read -t 600 -p "Pausing 10 minutes between Update and Upgrade" sudo apt -y upgrade read -t 600 -p "Pausing 10 minutes between Upgrade and AutoRemove" sudo apt -y autoremove 

Sometimes I get the below screen:

Terminal window with a curses-style interface showing a dialog labeled "Modified configuration file" asking whether changes should be retained or replaced

I also run this as a cron job (once a quarter) that calls the above script, but it fails when run via the cron. How can I recognize that this GUI prompt is up and input the right answer?

Important Note: This doesn't happen always, so I want it to recognize when it happens and only then provide the correct input.

8
  • Check if the package has a non-GUI installer script. Commented Sep 7, 2024 at 4:01
  • The site you're looking for is either Unix & Linux or Raspberry Pi. This is off-topic here, as it's not a programming question. Commented Sep 7, 2024 at 13:28
  • 1
    If you really want to ask the question, how do I write a bash script to respond to these GUI prompts, you'll have better luck asking with a use case where that's a good idea in the first place. For package management, to be honest, it's almost certainly not a good idea because you would need to foresee any possible interactive question that might come up, and that can change as stuff gets released, which is why package managers offer a non-interactive variant that just won't ask any questions. Commented Sep 7, 2024 at 14:01
  • 1
    You're coming at this from the wrong direction. The tool you're running has a noninteractive mode so there's no reason to automate input to it at all; just run it in the mode where it doesn't start the TUI (which isn't a GUI) in the first place. Commented Sep 7, 2024 at 14:34
  • 1
    askubuntu.com/questions/556385/… is the first hit searching "apt noninteractive" and it fits with how I remember solving this problem myself in the past. Commented Sep 7, 2024 at 16:15

1 Answer 1

1

For the specific case of dpkg frontends such as apt, it's built to be able to disable interactive prompts altogether -- you don't need to automate the prompts, you can just turn them off.

Export the environment variable DEBIAN_FRONTEND=noninteractive while you run apt, and you'll get no more interactive prompts; if you need to assert specific settings, you can set them noninteractively with utilities from debconf-utils -- see its documentation.

Concretely:

sudo DEBIAN_FRONTEND=noninteractive apt -y update read -t 600 -p "Pausing 10 minutes between Update and Upgrade" sudo DEBIAN_FRONTEND=noninteractive apt -y upgrade read -t 600 -p "Pausing 10 minutes between Upgrade and AutoRemove" sudo DEBIAN_FRONTEND=noninteractive apt -y autoremove 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.