Skip to content

Instantly share code, notes, and snippets.

@jalex19100
Created November 2, 2024 04:13
Show Gist options
  • Save jalex19100/ca3e434833810044e052b7edc4a61edf to your computer and use it in GitHub Desktop.
Save jalex19100/ca3e434833810044e052b7edc4a61edf to your computer and use it in GitHub Desktop.
Bare Bones (basic) Change password on unix server via Expect
#!/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