免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: whatislinux
打印 上一主题 下一主题

[文本处理] 看看 expect 执行,结果不能自动登录,提示invalid command name "~" [复制链接]

论坛徽章:
0
21 [报告]
发表于 2014-06-18 15:42 |只看该作者
回复 20# expert1


    非常感谢你的耐心回复,我再试试!

论坛徽章:
0
22 [报告]
发表于 2014-06-18 15:56 |只看该作者
回复 20# expert1


   我重新修改了下:
[abel.li@l-rtools1.ops.cn1 ~]$ cat ssh-hs01.sh
#!/usr/bin/expect -f  
set ip l-hs01.wap.cn1
set pw "v^@*8#3k8^z-@;~"
spawn ssh  abel.li@$ip

        set timeout 5

        send -- "$pw"

        expect "*#"
        send "exit\r"


debug信息:
[abel.li@l-rtools1.ops.cn1 ~]$ expect -d ssh-hs01.sh
expect version 5.43.0
argv[0] = expect  argv[1] = -d  argv[2] = ssh-hs01.sh  
set argc 0
set argv0 "ssh-hs01.sh"
set argv ""
executing commands from command file ssh-hs01.sh
spawn ssh abel.li@l-hs01.wap.cn1
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {22141}
send: sending "v^@*8#3k8^z-@;~" to { exp6 }

expect: does "" (spawn_id exp6) match glob pattern "*#"? no
v^@*8#3k8^z-@;~
expect: does "v^@*8#3k8^z-@;~" (spawn_id exp6) match glob pattern "*#"? yes
expect: set expect_out(0,string) "v^@*8#"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "v^@*8#"
send: sending "exit\r" to { exp6 }


请教下再怎样调试下,可以?

论坛徽章:
16
IT运维版块每日发帖之星
日期:2015-08-24 06:20:00综合交流区版块每日发帖之星
日期:2015-10-14 06:20:00IT运维版块每日发帖之星
日期:2015-10-25 06:20:00IT运维版块每日发帖之星
日期:2015-11-06 06:20:00IT运维版块每日发帖之星
日期:2015-12-10 06:20:00平安夜徽章
日期:2015-12-26 00:06:302016猴年福章徽章
日期:2016-02-18 15:30:34IT运维版块每日发帖之星
日期:2016-04-15 06:20:00IT运维版块每日发帖之星
日期:2016-05-21 06:20:00综合交流区版块每日发帖之星
日期:2016-08-16 06:20:002015七夕节徽章
日期:2015-08-21 11:06:17IT运维版块每日发帖之星
日期:2015-08-14 06:20:00
23 [报告]
发表于 2014-06-18 16:00 |只看该作者
你在terminal

ssh abel.li@你的ip,
看下输出是什么,然后把这个输出写到expect里面
比如输出是Enter xxxx
那么

set timeout 5
# 写这里,expect "xxxxx"
        send -- "$pw"

论坛徽章:
16
IT运维版块每日发帖之星
日期:2015-08-24 06:20:00综合交流区版块每日发帖之星
日期:2015-10-14 06:20:00IT运维版块每日发帖之星
日期:2015-10-25 06:20:00IT运维版块每日发帖之星
日期:2015-11-06 06:20:00IT运维版块每日发帖之星
日期:2015-12-10 06:20:00平安夜徽章
日期:2015-12-26 00:06:302016猴年福章徽章
日期:2016-02-18 15:30:34IT运维版块每日发帖之星
日期:2016-04-15 06:20:00IT运维版块每日发帖之星
日期:2016-05-21 06:20:00综合交流区版块每日发帖之星
日期:2016-08-16 06:20:002015七夕节徽章
日期:2015-08-21 11:06:17IT运维版块每日发帖之星
日期:2015-08-14 06:20:00
24 [报告]
发表于 2014-06-18 16:01 |只看该作者
此外,send pwd后有个\r回车啊。

论坛徽章:
0
25 [报告]
发表于 2014-06-18 16:09 |只看该作者
回复 23# expert1


    感谢,感谢,感谢!搞定了。终于有点明白了。谢谢

论坛徽章:
0
26
发表于 2014-06-18 16:11
回复 25# whatislinux


    [abel.li@l-rtools1.ops.cn1 ~]$ ./ssh-hs01.sh
spawn ssh abel.li@l-hs01.wap.cn1
Enter passphrase for key '/home/q/home/abel.li/.ssh/id_rsa':
Last login: Wed Jun 18 16:09:49 2014 from 192.168.0.59
[abel.li@l-hs01.wap.cn1 ~]$
大概等了5秒钟,就又回到了原来的主机上了。
[abel.li@l-rtools1.ops.cn1 ~]$
[abel.li@l-rtools1.ops.cn1 ~]$

这个怎么处理,?

论坛徽章:
0
27 [报告]
发表于 2014-06-18 16:12 |只看该作者
回复 26# whatislinux


    #!/usr/bin/expect -f  
set ip l-hs01.wap.cn1
set pw "v^@*8#3k8^z-@;~"
spawn ssh  abel.li@$ip

        set timeout 5
        expect "Enter passphrase for key '/home/q/home/abel.li/.ssh/id_rsa':"
        send -- "$pw\r"

        expect "*#"
        send "exit\r"

论坛徽章:
16
IT运维版块每日发帖之星
日期:2015-08-24 06:20:00综合交流区版块每日发帖之星
日期:2015-10-14 06:20:00IT运维版块每日发帖之星
日期:2015-10-25 06:20:00IT运维版块每日发帖之星
日期:2015-11-06 06:20:00IT运维版块每日发帖之星
日期:2015-12-10 06:20:00平安夜徽章
日期:2015-12-26 00:06:302016猴年福章徽章
日期:2016-02-18 15:30:34IT运维版块每日发帖之星
日期:2016-04-15 06:20:00IT运维版块每日发帖之星
日期:2016-05-21 06:20:00综合交流区版块每日发帖之星
日期:2016-08-16 06:20:002015七夕节徽章
日期:2015-08-21 11:06:17IT运维版块每日发帖之星
日期:2015-08-14 06:20:00
28 [报告]
发表于 2014-06-18 16:17 |只看该作者

看来不懂处理过程,瞎摸费时间啊。

论坛徽章:
0
29 [报告]
发表于 2014-06-18 16:26 |只看该作者
回复 28# expert1

[abel.li@l-rtools1.ops.cn1 ~]$ ./ssh-hs01.sh
spawn ssh abel.li@l-hs01.wap.cn1
Enter passphrase for key '/home/q/home/abel.li/.ssh/id_rsa':
Last login: Wed Jun 18 16:24:57 2014 from 192.168.0.59
[abel.li@l-hs01.wap.cn1 ~]$
整理已经跳转过去了,但是过了2秒又回到本地机器上了!
[abel.li@l-rtools1.ops.cn1 ~]$


   

论坛徽章:
16
IT运维版块每日发帖之星
日期:2015-08-24 06:20:00综合交流区版块每日发帖之星
日期:2015-10-14 06:20:00IT运维版块每日发帖之星
日期:2015-10-25 06:20:00IT运维版块每日发帖之星
日期:2015-11-06 06:20:00IT运维版块每日发帖之星
日期:2015-12-10 06:20:00平安夜徽章
日期:2015-12-26 00:06:302016猴年福章徽章
日期:2016-02-18 15:30:34IT运维版块每日发帖之星
日期:2016-04-15 06:20:00IT运维版块每日发帖之星
日期:2016-05-21 06:20:00综合交流区版块每日发帖之星
日期:2016-08-16 06:20:002015七夕节徽章
日期:2015-08-21 11:06:17IT运维版块每日发帖之星
日期:2015-08-14 06:20:00
30 [报告]
发表于 2014-06-18 16:36 |只看该作者
老办法debug看下。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP