歡迎您光臨本站 註冊首頁

expect+TCL實現批量機器SSH免登錄

←手機掃碼閱讀     火星人 @ 2014-03-03 , reply:0

expect+TCL實現批量機器SSH免登錄

分享一段expect+TCL自動化代碼,作用是在在任何一台Linux機器執行對其他Linux節點的免密碼登錄SSH:#!/usr/bin/expect
set ip
set passwd
spawn scp /root/.ssh/authorized_keys  root@$ip:/root/.ssh/authorized_key1
set i 1
while {$i<3} {
  expect {
    "password" {send "$passwd\n";set i 4}
    "yes" {send "yes\n"}
  }
}
expect eof

spawn ssh root@10.1.1.1
set j 1
while {$j<3} {
expect {
   "password" {send "abc123\n";set j 4}
   "yes"  {send "yes\n"}
   "]#" {send "exit\n"; set j 4}
}
}
expect "#"
send "hostname\n"
expect "#"
send "cat /root/.ssh/authorized_key1 >> /root/.ssh/authorized_keys\r"
expect "#"
send "exit\n"
expect eof
《解決方案》

呵呵,分享一下。
《解決方案》

感謝分享
http://blog.chinaunix.net/uid-11121450-id-322213.html
《解決方案》

thanks for you information!!!have a nice day!

[火星人 ] expect+TCL實現批量機器SSH免登錄已經有779次圍觀

http://coctec.com/docs/service/show-post-163.html