Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2045172
  • 博文数量: 354
  • 博客积分: 4955
  • 博客等级: 上校
  • 技术积分: 4579
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-21 11:46
文章分类

全部博文(354)

文章存档

2015年(1)

2013年(4)

2012年(86)

2011年(115)

2010年(67)

2009年(81)

我的朋友

分类: LINUX

2012-05-24 11:27:05

从网上看了几个脚本不错,借鉴一下

点击(此处)折叠或打开

  1. #!/bin/sh
  2. auto_login_ssh(){
  3. expect -c "
  4. set timeout -1;
  5. spawn -noecho ssh -o StrictHostKeyChecking=no $2 ${@:3};
  6. expect *assword:*;
  7. send -- $1\r;
  8. interact;"
  9. }
  10. auto_login_ssh password user@hostname

StrictHostKeyChecking=no参数让ssh默认添加新主机的公钥指纹,也就不会出现出现是否继续yes/no的提示了。


点击(此处)折叠或打开

  1. #!/usr/bin/expect
  2. # 解释器声明
  3. set timeout 30
  4. # 设置超时时间,单位秒
  5. spawn ssh test@192.168.1.1
  6. # spawn 是expect的内部命令,个人理解其作用就是宣告进入人机模拟开始
  7. expect "Password:"
  8. # expect也是内部命令,作用是监视终端输出是否包含后面的内容,有则执行下面的send,没有就等待上面设置的timeout时间
  9. send "123456\r"
  10. # 这个就是执行交互动作了,模拟人手动输入的东东,切记最后要带上回车符“\r”
  11. interact
  12. # 模拟结束,把控制权交还控制台,如果不加这个,就等于直接退出了

点击(此处)折叠或打开

  1. #!/usr/bin/expect
  2. set timeout 30
  3. spawn mysql -uroot -p
  4. expect "Enter password:"
  5. send "123456\r"
  6. interact



阅读(2857) | 评论(1) | 转发(0) |
0

上一篇:shc加密脚本

下一篇:mysql忘记密码

给主人留下些什么吧!~~

psop_sun2013-06-03 14:30:47

$ which expect ; ls -l /usr/bin/expect; cat test.sh ; sh test.sh     
/usr/bin/expect
-rwxr-xr-x 1 root root 11792 Oct 17  2011 /usr/bin/expect
  #!/usr/bin/expect -f
  set timeout 5
  spawn ssh localhost "pwd"
  expect "password:"
  send "xxxxxx\r"
  interact 
test.sh: line 1:   #!/usr/bin/expect: No such file or