I am setting up a cron job to update my Debian server box, and there is a potential problem. If I try upgrading from the terminal using apt -y upgrade
, even though there is the -y
option, when APT configures them, some packages display a ncurses prompt (or a Y/I/N/O/D/Z prompt) for random options that I always leave on default. How can these be avoided, if the command is not being run by me sitting in front of the computer, but by cron, with no way of user interaction?

- 111
1 Answers
I agree with Stephen Kitt's advice to use unattended-upgrades in the usual case of a running desktop/laptop/server.
Here's how I've dealt with this in scripts that were building a custom Amazon machine image (AMI) without waiting on unattended upgrades. This was on Ubuntu 16.x and 20.x using the lower-level apt-get
command, but I think it will work on Debian also.
E.g. a "dist-upgrade" command where a grub update may trigger a prompt to accept a new conf file or keep the old one:
DEBIAN_FRONTEND=noninteractive \
apt-get -y \
-o DPkg::Options::="--force-confold" \
-o DPkg::Options::="--force-confdef" \
dist-upgrade
I split the command across several lines to make it easier to read.
The environment variable setting DEBIAN_FRONTEND=noninteractive
is one ingredient that avoids prompts for a Y/I/N/O/D/Z answer. The other ingredient is to give dpkg
a clear indication of the option you want.
The --force-confold
and --force-confdef
are options to dpkg
. --force-confdef
chooses the default action if the package defines one. If a default is not defined, then --force-confold
chooses the old version, or --force-confnew
chooses the new version.
In my use case I wanted the old version.
More discussion and details in this previous question

- 4,131
-
In fact we should probably just make this a dupe of the older Q&A you found, it covers all the bases... – Stephen Kitt Aug 12 '22 at 17:13
-
It took me some time to find how to include the PPkg options in a .conf file in /etc/apt/apt.conf.d. This the the syntax: Dpkg::Options { "--force-confdef"; "--force-confold"; } The file can be named 80dpkg_forces.conf or so. The name is arbitrary, the .conf extension is mandatory. – Johannes Linkels Mar 12 '23 at 13:36