批量改变密码

950阅读 0评论2013-03-21 zhengsenlin888
分类:LINUX


  1. #!/usr/bin/expect

  2. set allhosts [open hosts.txt r]
  3. foreach all [read $allhosts] {
  4.     puts "$all"
  5.     set passwd "123456"
  6.     set newpasswd "12345678"
  7.     spawn /usr/bin/ssh root@$all
  8.     
  9.     expect {
  10.     "yes/no" { send "yes\r"; exp_continue}
  11.     "Password: " { send "$passwd\r" }
  12.     }

  13.     expect "#"
  14.     send "export LANG=\"en_US\"\r"

  15.     expect "#"
  16.     send "passwd\r"

  17.     expect "password:"
  18.     send "$newpasswd\r"

  19.     expect "password:"
  20.     send "$newpasswd\r"
  21. }
  22. expect eof
  23. close $allhosts

  24. exit

上一篇:perl ping代码
下一篇:bash shell多行注释