【发布时间】:2016-09-07 03:24:38
【问题描述】:
我正在尝试使用 pexpect 以用户身份登录并尝试打印所有可用的 cron:
import pexpect
import os, time
passwd = "mypass"
child = pexpect.spawn('su myuser')
child.expect('Password:')
child.sendline(passwd)
child.expect('$')
child.sendline('crontab -l')
i =child.expect(['%','.*$', '$' ])
print i # prints 1 here so, the shell is expected.
print child.before # this doesn't print anything though.
此代码似乎不起作用并打印空行。
- 无法找出这段代码的问题
- 如果有任何更好的方法来列出其他用户的 cron 作业,给定用户名和密码
任何指针或建议将不胜感激。
【问题讨论】:
标签: python python-2.7 subprocess crontab pexpect