亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
12下一頁
最近訪問板塊 發(fā)新帖
查看: 6694 | 回復(fù): 17
打印 上一主題 下一主題

expect不能自動登錄 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2010-09-08 15:46 |只看該作者 |倒序?yàn)g覽
本帖最后由 flyinsky191 于 2010-09-09 22:32 編輯

#!/usr/local/bin/expect

# 設(shè)置超時(shí)時(shí)間為 60 秒
set timeout  60
# 設(shè)置要登錄的主機(jī) IP 地址
set host 137.32.44.145
# 設(shè)置以什么名字的用戶登錄
set name Aiinweb
#spawn 一個(gè) ssh 登錄進(jìn)程
spawn  ssh $name@$host
# 等待響應(yīng),第一次登錄往往會提示是否永久保存 RSA 到本機(jī)的 know hosts 列表中;等到回答后,在提示輸出密碼;之后就直接提示輸入密碼
                                                                              
expect {
    "(yes/no)?" {
        send "yes\n"
        expect("Password:*"){
             send "AiAw#145\n"
       }
}
        "Password:*" {
        send "AiAw#145\n" 是密碼#的問題,有那么大俠能告知#號,在expect中的轉(zhuǎn)義字符是多少。謝謝。

    }
}

#expect eof           

執(zhí)行的結(jié)果是這樣的:

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2010-09-08 15:54 |只看該作者
expect {
        "No route" { exit }
        "want" {send -- "yes\r"; exp_continue}
        "password:" {send -- "密碼\r"}
        }

我試過這樣是沒問題的,不然你也試試?

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2010-09-08 16:02 |只看該作者
回復(fù) 2# david6102


    還是不行。還是到password就停了。

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2010-09-08 16:09 |只看該作者
沒好好看教程吧
需要一個(gè)while 循環(huán)
要不他只運(yùn)行一次

論壇徽章:
0
5 [報(bào)告]
發(fā)表于 2010-09-08 16:19 |只看該作者
回復(fù) 4# nuclearxin


    如果手工運(yùn)行ssh Aiinweb@137.32.44.145也只需要輸入一次密碼就可以了 。為什么要用while循環(huán)。每次都是到password之后就跳了出來。

論壇徽章:
0
6 [報(bào)告]
發(fā)表于 2010-09-08 16:20 |只看該作者
spawn ssh -p7710 用戶名@IP
expect "password:"
send "密碼\r"
interact

論壇徽章:
0
7 [報(bào)告]
發(fā)表于 2010-09-08 16:26 |只看該作者
回復(fù) 6# yangyang1581


#!/usr/local/bin/expect

spawn ssh -p22 Aiinweb@137.32.44.145
expect "*assword:"
send "AiAw#145\r"
interact


我是這樣寫的?墒且恢碧崾綪assword,多輸入幾次密碼之后就成這樣了
spawn ssh -p22 Aiinweb@137.32.44.145
Password:
Password:
Password:
Aiinweb@137.32.44.145's password:
Permission denied, please try again.
Aiinweb@137.32.44.145's password: .

論壇徽章:
0
8 [報(bào)告]
發(fā)表于 2010-09-08 16:30 |只看該作者
expect 用起來確實(shí)有點(diǎn)別扭.... 不過在python 中  pexpect 的模塊做的比較好,,, 有機(jī)會可以去嘗試下 至于shell 下的

spawn ssh $IP $CMD
expect  {
    "*continue connecting (yes/no)?*"
    {
    send "yes\r"
    exp_continue
    }
    "*password*"
    {
    send "$PWD\r"
    exp_continue
    }
    "*Last login*"
     {
    interact
    exit 0
    }
    eof
    {
    exit 1
    }
僅供參考......

論壇徽章:
0
9 [報(bào)告]
發(fā)表于 2010-09-08 16:50 |只看該作者
我的腳本是:
#!/usr/local/bin/expect -d

spawn ssh -p22 Aiinweb@137.32.44.145
expect "*?assword:*"
send "AiAw#145\r"

interact




執(zhí)行的時(shí)候顯示:
/kt1/xiao% ./zidong.sh
expect version 5.43.0
argv[0] = /usr/local/bin/expect  argv[1] = -d  argv[2] = ./zidong.sh  
set argc 0
set argv0 "./zidong.sh"
set argv ""
executing commands from command file ./zidong.sh
spawn ssh -p22 Aiinweb@137.32.44.145
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {25410}

expect: does "" (spawn_id exp7) match glob pattern "*?assword:*"? no
Password:
expect: does "Password: " (spawn_id exp7) match glob pattern "*?assword:*"? yes
expect: set expect_out(0,string) "Password: "
expect: set expect_out(spawn_id) "exp7"
expect: set expect_out(buffer) "Password: "
send: sending "AiAw#145\r" to { exp7 }
tty_raw_noecho: was raw = 0  echo = 1
spawn id exp7 sent <\r\n>

spawn id exp7 sent <Password: >
Password:

論壇徽章:
0
10 [報(bào)告]
發(fā)表于 2010-09-08 17:18 |只看該作者
參考下我的  
我的是自動升級OS的,升級過程中會重啟。重啟這段時(shí)間就after ,重新登陸后還有等待OS一致后才繼續(xù)下個(gè)版本升級
  1. set ipAddr [lindex $argv 0]
  2. set FTP [lindex $argv 1]
  3. spawn telnet $ipAddr
  4. log_file update.log
  5. expect "login:"
  6. send "admin\r"
  7. expect "Password:"
  8. send "password\r"
  9. expect ">"
  10. send "\003"
  11. expect ">"
  12. send "firmwareshow\r"
  13. expect ">"
  14. send "firmwaredownload\r"
  15. expect "*Do you want to continue*:"
  16. send "y\r"
  17. expect "Server Name or IP Address:"
  18. send "172.16.16.16\r"
  19. expect "User Name:"
  20. send "root\r"
  21. expect "File Name:"
  22. send "./v5.2.3/release.plist\r"
  23. expect "Password:"
  24. send "huawei\r"
  25. expect "*Do you want to continue*:"
  26. send "\r"
  27. set timeout 3000
  28. expect "*HA Rebooting*"
  29. after 120000
  30. spawn telnet $ipAddr
  31. expect "login:"
  32. send "admin\r"
  33. expect "Password:"
  34. send "password\r"
  35. expect ">"
  36. send "\003"
  37. expect ">"
  38. send "firmwareshow\r"
  39. after 60000
  40. expect ">"
  41. send "firmwareshow\r"
  42. after 60000
  43. expect ">"
  44. send "firmwareshow\r"
  45. expect ">"
  46. send "firmwaredownload\r"
  47. expect "Server Name or IP Address:"
  48. send "172.16.16.16\r"
  49. expect "User Name:"
  50. send "root\r"
  51. expect "File Name:"
  52. send "./v5.3.2a/release.plist\r"
  53. expect "Password:"
  54. send "huawei\r"
  55. expect "*Do you want to continue*:"
  56. send "y\r"
  57. set timeout 3000
  58. expect "*HA Rebooting*"
  59. after 120000
  60. spawn telnet $ipAddr
  61. expect "login:"
  62. send "admin\r"
  63. expect "Password:"
  64. send "password\r"
  65. expect ">"
  66. send "\003"
  67. expect ">"
  68. send "firmwareshow\r"
  69. expect ">"
  70. send "firmwareshow\r"
  71. after 120000
  72. expect ">"
  73. send "firmwareshow\r"
  74. after 120000
  75. expect ">"
  76. send "firmwareshow\r"
  77. expect ">"
  78. send "firmwaredownload\r"
  79. expect "Server Name or IP Address:"
  80. send "172.16.16.16\r"
  81. expect "User Name:"
  82. send "root\r"
  83. expect "File Name:"
  84. send "./v6.0.1a/release.plist\r"
  85. expect "*FTP*"
  86. send "2\r"
  87. expect "Password:"
  88. send "huawei\r"
  89. expect "*Do you want to continue*:"
  90. send "y\r"
  91. set timeout 3000
  92. expect "*HA Rebooting*"
  93. after 120000
  94. spawn telnet $ipAddr
  95. expect "login:"
  96. send "admin\r"
  97. expect "Password:"
  98. send "password\r"
  99. expect ">"
  100. send "\003"
  101. expect ">"
  102. send "firmwareshow\r"
  103. after 60000
  104. expect ">"
  105. send "firmwareshow\r"
  106. after 60000
  107. expect ">"
  108. send "exit\r"
  109. expect eof
復(fù)制代碼
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP