在远程计算机上使用 rsh 运行命令
我正在尝试运行 python 脚本,并且需要从脚本中执行 Rsh 命令,我要运行的命令是: df -Pk|grep "sd\|md"|gawk '{print $2}'
我这样做 -
cmd2='df -Pk|grep \\\"sd\|md\\\"|gawk \'{print $2}\''
process = subprocess.Popen(['rsh',ip,cmd2],stdout=subprocess.PIPE)
output = process.communicate()[0]
但是当我运行脚本时,我没有得到任何输出。
我是 python 新手,据我所知,这是转义字符的问题。
任何帮助都会很棒。
笔记: 我只能使用 Rsh,不能使用 ssh
谢谢
I am trying to run a python script, and I need to Rsh a command from the script, the command I want to run is : df -Pk|grep "sd\|md"|gawk '{print $2}'
and I do it as -
cmd2='df -Pk|grep \\\"sd\|md\\\"|gawk \'{print $2}\''
process = subprocess.Popen(['rsh',ip,cmd2],stdout=subprocess.PIPE)
output = process.communicate()[0]
However when I do run the script,I get nothing in output.
I am new to python and as far as I know, its a problem with the escape characters.
Any help would be great.
Note:
I have to use Rsh only and cannot use ssh
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用正确的 shell 引用将命令括在三引号中:
另请参阅 Python 教程的 bit on字符串。
Enclose the command, with proper shell quoting, in triple quote marks:
See also the Python tutorial's bit on strings.