This shows you the differences between two versions of the page.
remote_password_change [2011/05/02 00:14] k2patel |
remote_password_change [2020/08/10 02:35] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ==== Change User password remotely ==== | ||
- | <code bash> | ||
- | #!/usr/bin/expect | ||
- | # usage: runcmd <command> <password> | ||
- | # | ||
- | # NB: be sure to surround the command with double quotes | ||
- | # if the command string is more than 1 word | ||
- | # | ||
- | set timeout 30 | ||
- | set fid [open /root/utilz/scripts/hosts r] | ||
- | set contents [read -nonewline $fid] | ||
- | close $fid | ||
- | |||
- | set cmd [lindex $argv 0] | ||
- | set password [lindex $argv 1] | ||
- | set newpass [lindex $argv 2] | ||
- | foreach host [split $contents "\n"] { | ||
- | spawn ssh -l root $host | ||
- | expect { | ||
- | "assword:" { | ||
- | send -- "$password\r" | ||
- | } | ||
- | "you sure you want to continue connecting" { | ||
- | send -- "yes\r" | ||
- | expect "assword:" | ||
- | send -- "$password\r" | ||
- | } | ||
- | } | ||
- | expect "#" | ||
- | send -- "$cmd\r" | ||
- | expect "assword:" | ||
- | send "$newpass\r" | ||
- | expect "assword:" | ||
- | send "$newpass\r" | ||
- | expect "#" | ||
- | send -- "exit\r" | ||
- | </code> |