hhnf333 发表于 2018-7-30 11:43:48

ansible 自动ssh

#!/usr/bin/expect -f  
set timeout -1
  
set user test
  
set passwd "123456"
  

  
for { set i 100 } { $i < 120 } { incr i } {
  
    spawn ssh -l $user 172.41.30.$i
  
    expect {
  
      "yes/no" { send "yes\r";exp_continue }
  
      "id_rsa" { send "yes\r";exp_continue }
  
      "*assword" { send "$passwd\r" ;exp_continue }
  
      "test@" {
  
      send "sudo su -\r"
  
      expect {
  
            "password for test" { send "$passwd\r";exp_continue }
  
            }
  
      }
  
    }
  
}
  
expect eof
  
exit 0
页: [1]
查看完整版本: ansible 自动ssh