94

I am building a provisioning script for a ubuntu vagrant vm, on a ubuntu host, both 12.10 64bit When installing the following packages:

sudo apt-get -y install php5-xsl graphviz php-pear unison

I get the warning:

dpkg-reconfigure: unable to re-open stdin: No file or directory

have tried searching but results are throwing up every other error with apt-get possible, can't find out how to supress the warning above. The installs work, but the warning above is causing error lines in the vagrant up stdout.

Anybody any idea what could be the cause or how to suppress the warning

BMW
  • 103
  • 3
Daithí
  • 1,333
  • 1
  • 11
  • 14

4 Answers4

117

I got the error message to go away by putting the following in my provisioning script, prior to any apt-get calls:

export DEBIAN_FRONTEND=noninteractive

This makes debconf use a frontend that expects no interactive input at all, preventing it from even trying to access stdin.

der_gabe
  • 1,271
  • 2
  • 8
  • 3
25

The answer was to set the perl:locale's as per this:

export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale-gen en_US.UTF-8
dpkg-reconfigure locales

This solves the issue, but does add unwanted time to the vagrant up provisioning.

kenorb
  • 5,943
  • 1
  • 44
  • 53
Daithí
  • 1,333
  • 1
  • 11
  • 14
  • 2
    This alone did not work for me. I still got the warning until I implemented @kenorb's `70debconf` commenting-out fix for preconfigure. – notbrain Aug 31 '15 at 21:18
  • My question is: Is it fine to ignore these warnings? @Coombesy – Marco Prins Sep 23 '15 at 07:07
  • @MarcoPrins Yes, you can safely ignore warnings like "stdin: is not a tty" or "dpkg-preconfigure: unable to re-open stdin: No such file or directory". One of numerous confirmations around can be found, e.g. here https://www.ikusalic.com/blog/2013/10/03/vagrant-intro/ – mloskot Nov 01 '15 at 18:22
10

Run this command:

cat /etc/apt/apt.conf.d/70debconf 

to see if you've this file. If so, the solution is to comment out the DPkg line which prevents pre-configuring all packages with debconf before they are installed.

So add these commands to your provision file:

sudo ex +"%s@DPkg@//DPkg" -cwq /etc/apt/apt.conf.d/70debconf
sudo dpkg-reconfigure debconf -f noninteractive -p critical

Otherwise if you don't care about this file, simply remove it:

sudo rm -v /etc/apt/apt.conf.d/70debconf

Here are few other commands to consider, but I don't think they do anything useful:

sudo dpkg-preconfigure -f noninteractive -p critical
sudo dpkg --configure -a
kenorb
  • 5,943
  • 1
  • 44
  • 53
  • 1
    This is what finally worked for me on OSX Yosemite Vagrant and Ubuntu 14.04. – notbrain Aug 31 '15 at 21:13
  • You may still need to change the shell Vagrant uses. – Marshall Davis Sep 02 '15 at 19:23
  • 1
    Messing with this file was the only thing that worked for me (obviously ignoring the "redirect stderr" suggestions, which I think is bad advice). I elected to use a before/after pair of provisioning steps to temporarily include the `--frontend=noninteractive` option in the command defined in the file. `sudo sed -i 's/\(dpkg-preconfigure\) --apt/\1 --frontend=noninteractive --apt/' /etc/apt/apt.conf.d/70debconf` before, and `sudo sed -i 's/ --frontend=noninteractive//' /etc/apt/apt.conf.d/70debconf` after. – phils Jul 03 '19 at 11:57
5

Bash redirection works fine for stdout and stderr.

To redirect the error stream, use the following:

sudo apt-get -y install php5-xsl graphviz php-pear unison 2> /dev/null

To redirect both stdout (messages that are not errors/warnings) and stderr both, use:

sudo apt-get -y install php5-xsl graphviz php-pear unison &> /dev/null

That is a shortcut available in bash for this:

sudo apt-get -y install php5-xsl graphviz php-pear unison > /dev/null 2>&1

Or:

sudo apt-get -y install php5-xsl graphviz php-pear unison 1> /dev/null 2>&1

Below, we can clearly see that file descriptor 1 is stdout, 2 stderr, 3 stdin.

$ ls -l /dev/std*
lrwxrwxrwx 1 root root 15 Apr 18 19:03 /dev/stderr -> /proc/self/fd/2
lrwxrwxrwx 1 root root 15 Apr 18 19:03 /dev/stdin -> /proc/self/fd/0
lrwxrwxrwx 1 root root 15 Apr 18 19:03 /dev/stdout -> /proc/self/fd/1

So for what you are saying you want to do, you should only need the very first command I gave.

BullShark
  • 64
  • 2
  • 1
    I want to be able to echo the normal stdout from apt-get. But you may have me on the right track... i'll try sending just the stderr to the bit-bucket - cheers edit: we both commented at the same time lol - cheers (again) – Daithí Apr 19 '13 at 01:34
  • I edited the post. See the very last line. – BullShark Apr 19 '13 at 01:45