~「為響應政府網路分級制度,本站全部內容均為限制級」~

訓練家的快寫筆記

The legend of trainer's paper


搜尋:

     關閉     
標題:expect 自動登入的小技巧 模擬鍵盤輸入
內容:


 expect -c 'spawn ssh root@3wa.tw ; expect assword ; send "1234567\n" ; expect 3wa;send "logout\n" ; interact'


ssh 自動登入的小技巧

#!/usr/bin/expect 

spawn ssh www.president.gov.tw
expect "*Yes*"
send "yes\n"
expect "*password:*"
send "MaInNine\n"
expect "localhost"
send "ls\n"
expect eof

# aaa.exp
#!/usr/bin/expect 
spawn ssh [lindex $argv 0]
expect "password:"
send [lindex $argv 1]
send "\n"
expect "localhost"
send [lindex $argv 2]
send "\n"
expect eof