Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm writing a script in Python, which is connecting to server via ssh, then installing some packages. But there is problem with dialogue box, where i can type in a root password- i don't know how to send data there. Once I tried to do this, my apt(using Debian Lenny) gone crazy.

Here is some info: - Debian Lenny - Using PySSH with easier interface, code looks like this:

clientSSH = SSHClient( self.ip, 'root', self.rootPassword, None )
clientSSH.run_command('apt-get install mysql-server mysql-client php5')
#I Don't know how send root passwd here
share|improve this question
After rereading this, it might be a little ambiguous. Are you setting the MySQL root password? What do you mean by a 'dialogue box', certainly it is just a prompt expecting input? Box makes me think ncurses. – Sam Halicke Nov 18 '09 at 16:26
Dialogue box= ncurses box with prompt about root password. It shows when dpkg is configuring mysql-server – mrbox Nov 18 '09 at 16:56

Use apt-get -y

  • see apt-get(1)

And for SSH if you're not: use password-less ssh keys

share|improve this answer
I'd promise that i tried with this option too- but it could be done after apt crash and maybe there were sth wrong. So, the next try will be on clean system, with -y option. – mrbox Nov 18 '09 at 16:30

I would suggest trying:

apt-get -y install mysql-server mysql-client php5

The -y switch answers yes to all questions by default.

As far as the root password for MySQL goes, you may have to use a module like Pexpect to send the password, if you find yourself unable to pipe it through PySSH or cannot reliably determine when to send it.

updated answer:

I researched this a little and it seems you have a couple choices, both pretty involved on your part:

  1. Use Pexpect.
  2. Build a custom .deb that removes the password prompt from the "postinst" script
  3. Use apt-get and dpkg to unpack but not configure MySQL.

Option 1: Rewrite your script to use Pexpect (this should be able to handle ncurses)

Option 2:

# get the original .deb: 
apt-get -y --download-only -q install mysql-server
# need a tempdir for this
mkdir ~/tmp;cd ~/tmp
cp /var/cache/apt/mysql-version.deb .
ar -x mysql-version.deb
mkdir DEBIAN
tar xf control.tar.gz -C DEBIAN
vim DEBIAN/postinst
# edit the lines about prompting for rootpw in here and replace $rootpw with what you want, 
# or however you choose to accomplish this
tar xf data.tar.gz -C .
dpkg-deb -b . mysql-server-version-noprompt.deb

And there's your new .deb. I haven't tested it, so YMMV.

Option 3:

# Skip postinst entirely
apt-get -q -y --download-only mysql-server
dpkg --unpack /var/cache/apt/mysql-server-version.deb
# instead of dpkg you can use dpkg-deb:
dpkg-deb -X /var/cache/apt/mysql-server-version.deb /

This will skip the postinstall entirely -- have a look at the script to see what it does, then repeat those steps.

share|improve this answer
The same as @phil – mrbox Nov 18 '09 at 16:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.