8

I have a simple bash script that connects to a series of servers and updates a specific package, using a here-string to answer a prompt:

sudo /usr/bin/apt-get install package-name <<< Y

The prompt is:

Configuration file /etc/package-name/package-name.conf
==> File on system created by you or by a script.
==> File also in package provided by package maintainer.
  What would you like to do about it? Your options are:
  Y or I : install the package maintainer's version
  N or O : keep your currently-installed version
    D    : show the differences between the versions
    Z    : background this process to examine the situation
 The default action is to keep your current version.
*** package-name.conf (Y/I/N/O/D/Z [default=N] ?

This is the error when it doesn't work:

dpkg: error processing package-name (--configure):
EOF on stdin a conffile prompt
Errors were encountered while processing:
package-name

I'm not able to install expect or any other programs on the servers. Any help would be appreciated.

kenorb
  • 155,785
  • 88
  • 678
  • 743
fja
  • 91
  • 1
  • 5

2 Answers2

18

You should pass in a dpkg option to specify at the prompt the desired behavior in this scenario. Then it won't prompt.

sudo apt-get -o DPkg::Options::="--force-confnew" -y install package-name

(Untested; obtained by googling.)

Griwes
  • 8,805
  • 2
  • 43
  • 70
tripleee
  • 175,061
  • 34
  • 275
  • 318
  • 2
    This worked, tripleee - thanks. I modified the command to: `sudo apt-get -o DPkg::Options::="--force-confnew" install package-name` – fja Aug 23 '11 at 14:55
  • 3
    For opposite, use: `--force-confold`. – kenorb Oct 27 '17 at 17:06
  • see also: https://askubuntu.com/questions/104899/make-apt-get-or-aptitude-run-with-y-but-not-prompt-for-replacement-of-configu – Daniel777 Aug 16 '18 at 12:54
2

If you look at the apt-get man page, you can find an option (-y) to answer yes for you. Why not try that.

ghostdog74
  • 327,991
  • 56
  • 259
  • 343
  • sorry - should have mentioned that I tried that. It doesn't work in this case. – fja Aug 23 '11 at 04:43
  • dpkg: error processing package-name (--configure): EOF on stdin a conffile prompt Errors were encountered while processing: package-name – fja Aug 23 '11 at 04:54
  • you just do `sudo /usr/bin/apt-get install -y package-name` (not tested) without the `<<<` – ghostdog74 Aug 23 '11 at 05:18
  • `apt-get install -y, --yes, --assume-yes` do not work in this case. – fja Aug 23 '11 at 06:10
  • As an alternative, if you need to answer with a capital Y, or some other string, you could use `yes`. Invoked as `yes`, it will print `y` at all prompts. If `yes `, it will print `` instead. – carlpett Aug 23 '11 at 06:46
  • The `-y` flags were among the first things I tried; it doesn't even work on the command line in this case. Thanks, though; I know I provided limited info. – fja Aug 23 '11 at 14:54
  • @carlpett Probably don't do that; the reason there's are explicit command-line options to avoid using a pipe from `yes` is that you can't know, in the general case, what you are replying to (it could be asking for your domain name, time zone, database password, etc etc) – tripleee Jul 24 '23 at 10:20