您的位置:首页 > 其它

使用expect脚本登录到root账号并执行命令

2011-04-20 10:22 435 查看
通过expect脚本登录root账号,方法比较简单,只要先写一个如下格式的脚本即可:

#!/usr/bin/expect
set timeout=5                       #设置5秒超时
spawn sudo su
expect "*assword*"
send    "123456\r"                   #发送密码,别忘了以\r结尾
expect "*#*"                           #等待#提示符的出现
send    "ls -l>/tmp/1\r"
expect "*#*"
send     "uname -a>/tmp/2\r"
#interact                              #使用interact后,脚本将退出到root账号下,可以手动执行root权限的命令
expect  eof
exit


参考:
http://freebsder.blog.163.com/blog/static/1041573201021510155036/ http://www.examda.com/linux/fudao/20100728/102721675.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐