我正在用Python编写一个脚本,通过ssh连接到服务器,然后安装一些软件包。 但有对话框的问题,我可以input一个root密码 – 我不知道如何发送数据。 一旦我试图做到这一点,我的apt(使用Debian Lenny)疯了。
这里是一些信息: – Debian Lenny – 使用PySSH更简单的界面,代码如下所示:
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()
我会build议尝试:
apt-get -y install mysql-server mysql-client php5
-y开关默认回答是所有问题。
就MySQL的root密码而言,如果您发现自己无法通过PySSH进行pipe道传输,或者无法可靠地确定何时传送密码,则可能必须使用像Pexpect这样的模块来发送密码。
更新回答:
我研究了这一点,似乎你有几个select,你都有相当的参与:
选项1:重写脚本以使用Pexpect(这应该能够处理ncurses)
选项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
还有你的新的.deb。 我没有testing过,所以YMMV。
备选案文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 /
这将完全跳过安装后的安装 – 查看脚本以查看它的作用,然后重复这些步骤。