运行csh脚本时让python输入密码 [英] Make python enter password when running a csh script

查看:171
本文介绍了运行csh脚本时让python输入密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个Python脚本,该脚本在Solaris 10中执行csh脚本.csh脚本提示用户输入root密码(我知道),但是我不确定如何使python脚本通过以下方式回答提示:密码.这可能吗?这是我用来执行csh脚本的内容:

I'm writing a python script that executes a csh script in Solaris 10. The csh script prompts the user for the root password (which I know) but I'm not sure how to make the python script answer the prompt with the password. Is this possible? Here is what I'm using to execute the csh script:

import commands

commands.getoutput('server stop')

推荐答案

看看 pexpect 模块.它旨在处理交互式程序,这似乎是您的情况.

Have a look at the pexpect module. It is designed to deal with interactive programs, which seems to be your case.

哦,请记住,在shell或python脚本中对根密码进行硬编码可能是一个安全漏洞:D

Oh, and remember that hard-encoding root's password in a shell or python script is potentially a security hole :D

这篇关于运行csh脚本时让python输入密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆