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.login() clientSSH.run_command('apt-get install mysql-server mysql-client php5') clientSSH.run_command('Y') #I Don't know how send root passwd here clientSSH.logout()
Use apt-get -y
And for SSH if you're not: use password-less ssh keys
I would suggest trying:
apt-get -y install mysql-server mysql-client php5
-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.
I researched this a little and it seems you have a couple choices, both pretty involved on your part:
- Use Pexpect.
- Build a custom .deb that removes the password prompt from the "postinst" script
- 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)
# 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
tar xf control.tar.gz -C DEBIAN
# 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.
# 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.