expect
配合  console 作變化                                                    
自已作一個文檔
要改的時候就用貼的
#/.updat_root_passwd.exp           Host              user        userpwd     rootpwd        newpwd
/script/updat_root_passwd.exp  192.168.1.1  c9992         pwd                 GOD            dog
/script/updat_root_passwd.exp  192.168.1.2  c9992         pwd                 GOD            dog
#!/usr/local/bin/expect
#scriptname : updat_root_passwd.exp
set HOSTNAME  [lindex $argv 0]
set USERNAME  [lindex $argv 1]
set USERPASSWD   [lindex $argv 2]
set ROOTPASSWD   [lindex $argv 3]
set NEWROOTPASSWD   [lindex $argv 4]
spawn ssh $USERNAME@$HOSTNAME
expect "*assword:*"
send "$USERPASSWD\r"
expect "*>*"
send "su \r"
expect "*assword:*"
send "$ROOTPASSWD\r"
expect "*#*"
send "passwd root\r"
expect "*assword:*"
send "$NEWROOTPASSWD\r"
expect "*assword:*"
send "$NEWROOTPASSWD\r"
expect "*passwd: password successfully changed for root*"
exit
 
 
沒有留言:
張貼留言