免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2890 | 回复: 5
打印 上一主题 下一主题

[系统管理] 求助: 关于 expect 变量传递给 shell. [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-09-20 15:00 |只看该作者 |倒序浏览

  1. #!/bin/bash
  2. #
  3. #
  4. iplist=`ifconfig  | awk '/inet addr/{print $2}' | awk -F: '{print $NF}' | grep -v "127.0.0.1"`
  5. port="22"
  6. password="123"
  7. password2="1234"
  8. password3="123456"

  9. for y in 192.168.3.164
  10. do

  11.     expect<<!
  12.       spawn ssh root@$ip.$y -p $port \"hostname\"
  13.         expect {
  14.           "yes/no" { send "yes\r" ; exp_continue }
  15.           "password" { send "$password\r" ;
  16.             expect {
  17.               "password" { send "$password2\r" ;
  18.                 expect {
  19.                   "password" { send "$password3\r" ; exp_continue }
  20.                 }
  21.               }
  22.             }
  23.           }
  24.         }
  25.      set info \$expect_out(buffer)
  26. !
  27.    echo $info
  28. done
复制代码
shell 获取不到 expect 的变量,请问我应该如何做?

论坛徽章:
0
2 [报告]
发表于 2012-09-20 16:15 |只看该作者
顶一下,等待...

论坛徽章:
0
3 [报告]
发表于 2012-09-20 17:58 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
4 [报告]
发表于 2012-09-21 11:02 |只看该作者
贴别沉呀,各位

论坛徽章:
0
5 [报告]
发表于 2012-09-24 12:04 |只看该作者
chinaunix... 已经第四天了,看看第几天能有人回答....

论坛徽章:
0
6 [报告]
发表于 2012-09-25 00:04 |只看该作者
结贴:

chinaunix 让我太失望了,我不得不离开你...
既然我找到的答案,还是要有始有终,把答案贴出来共享给大家.

参考链接:
http://stackoverflow.com/questio ... printing-out-buffer
  1.     #!/bin/bash
  2.     #
  3.     #
  4.     port="22"
  5.     password="123"
  6.     password2="1234"
  7.     password3="123456"

  8.     for y in 192.168.0.121
  9.     do
  10.         output=`expect -c "
  11.           log_user 0
  12.           spawn ssh root@$y -p $port hostname
  13.             expect {
  14.               \"yes/no\" { send \"yes\r\" ; exp_continue }
  15.               \"password\" { send \"$password\r\" ;
  16.                 expect {
  17.                   \"password\" { send \"$password2\r\" ;
  18.                     expect {
  19.                       \"password\" { send \"$password3\r\" ; exp_continue }
  20.                     }
  21.                   }
  22.                 }
  23.               }
  24.             }
  25.           puts \\$expect_out(buffer)
  26.     "`
  27.        echo $output
  28.     done
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP