Created
November 2, 2024 04:13
-
-
Save jalex19100/ca3e434833810044e052b7edc4a61edf to your computer and use it in GitHub Desktop.
Bare Bones (basic) Change password on unix server via Expect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/expect -f | |
# | |
# Usage: <scriptname> <username> <existingpassword> <newpassword> <servername/host> | |
set timeout 10 | |
set username [lindex $argv 0] | |
set password [lindex $argv 1] | |
set newpassword [lindex $argv 2] | |
set serverid [lindex $argv 3] | |
spawn ssh -a -oIdentitiesOnly=yes -oStrictHostKeyChecking=no $username@$serverid | |
# Uppercase or lowercase P? | |
expect "assword:" | |
send "$password\r" | |
expect "(current) UNIX password:" | |
send "$password\r" | |
expect "New UNIX password:" | |
send "$newpassword\r" | |
expect "Retype new UNIX password:" | |
send "$newpassword\r" | |
send "" | |
expect eof |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment