expect
来源:互联网 发布:xampp中mysql定时重启 编辑:程序博客网 时间:2024/05/29 23:23
参考 https://github.com/tzlwin/my-scripts/tree/master/expect_scripts
http://inguza.com/document/expect-and-tcl-mini-reference-manual expect-manual
http://bbs.chinaunix.net/thread-3566066-1-1.html FAQ
http://bbs.chinaunix.net/thread-639081-1-1.html FAQ
http://bbs.chinaunix.net/thread-594417-1-1.html FAQ
http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=674903&page=1#pid4559521
http://linux.chinaunix.net/techdoc/beginner/2009/03/02/1100264.shtml zh_cn manual
http://www.tcl.tk/man/tcl8.5/tutorial/tcltutorial.html TCL-GOV
!/usr/bin/expect
su ssh deploy multideploy
exp_internal 1 调试信息
1 命令参数
http://www.startos.com/linux/tips/2011010720609.html
参数 -d 调试 -b 逐条执行
expect可以让你使用“-c”选项,直接在命令行中执行它,如下所示:
$ expect -c ‘expect “\n” {send “pressed enter\n”} 按下回车后,打印出press…
用spawn来执行一条shell命令,不然你的输出都没用。 -noecho 参数表示没有回显
send_user 相当于echo 让界面显示的内容
#
2 接收输入参数
set a [lindex
set arg [append arg
3 计算
[expr 2-1]
4 控制语句
5 函数
proc do_login {login pass} { # 这个{不能换行
…………
}
5 调用shell变量
!/usr/bin/expect -fset password 123456set date [exec date "+%Y-%m-%d"]spawn /usr/bin/scp root@1.1.1.1://backup/test-file-$date /test/backup/expect "assword:"send -- "$password\r"expect "assword:"send -- "$password\r"expect eof
返回结果给shell
expect 返回值给bash,expect中 system “echo a”
expect 详解
这样是并行匹配,也是比较推荐的一种
exp_continue 是继续循环匹配
expect { "assword" { send_user "sudo now\n" send "$passwd\n" exp_continue } eof { send_user "eof\n" }}
命令匹配以$ $ 来匹配所有内容
字符串操作
文件操作
打开文件 set file [open tools.ret w+]
写入文件 puts file “success”
读取文件
if {[file isfilefile]!=1}
{
send_user “
”
exit }}
- Expect
- expect
- expect
- expect
- Expect
- expect
- expect
- expect
- expect
- expect
- expect
- expect
- expect
- expect
- expect
- expect
- expect
- expect
- 关于道格拉斯算法的一些思考
- 安装、配置、使用kermit
- RC522 读卡器和写卡器 读写测试程序----基于cc2530开发板
- 太上感应篇0005
- leetcode笔记:Subsets II
- expect
- Java 去除字符串中多余的空格,只留一个
- UIScrollView新手教程
- 计算机编程语言发展史
- 大师带你学大数据
- 太上感应篇0006
- HDU1530 【最大团 水】
- sql之left join、right join、inner join的区别
- juqery.form.js在提交表单前修改某个值的方法