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

来源:互联网 发布:linux编译c程序错误 编辑:程序博客网 时间:2024/04/28 18:40

通过expect脚本登录root账号,方法比较简单,只要先写一个如下格式的脚本即可:

 

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

 

 

 

参考:

http://freebsder.blog.163.com/blog/static/1041573201021510155036/

 

http://www.examda.com/linux/fudao/20100728/102721675.html

原创粉丝点击