Forked from anonymous/gist:73432240e4ed4361e398dde64dc2877d
Last active
March 2, 2018 22:54
-
-
Save apeace/7d394d34746836b9164f8dc819176116 to your computer and use it in GitHub Desktop.
This file contains 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
// Intended usage: ./change-password.pxr <username> <oldPass> <newPass> | |
retcode ERR_SSH_FAILED 1 "Failed to ssh to $host: $output" | |
retcode ERR_UNKNOWN_PWD_OUTPUT 2 "The `passwd` command returned an unexpected output: $output" | |
retcode ERR_WRONG_PASSWORD 3 "The given oldPass is wrong" | |
retcode ERR_PASSWORD_DIDNT_SUCCEED 4 "The `passwd` command accepted the input but didn't succeed: $output" | |
retcode ERR_CONFIRM_DIDNT_SUCCEED 5 "The `passwd` confirmation accepted the input but didn't succeed: $output" | |
retcode ERR_UNKNOWN_SUDO_OUTPUT 6 "The `sudo` command returned an unexpected output: $output" | |
ssh andrew@foo.bar.baz | |
case prompt next | |
else return ERR_SSH_FAILED | |
send "passwd $username" | |
runPwd($argv[0], $argv[1], $argv[2]) | |
case success next | |
case "You are not root" return rootPwd($argv[0], $argv[1], $argv[2]) | |
else return $! | |
def runPwd ($username, $oldPass, $newPass) { | |
default return ERR_UNKNOWN_PWD_OUTPUT | |
case "Enter $username's password" { | |
send $oldPass | |
case success next | |
else return ERR_WRONG_PASSWORD | |
} | |
case "Enter $username's new password { | |
send $newPass | |
case success next | |
else return ERR_PASSWORD_DIDNT_SUCCEED | |
} | |
case "Confirm $username's new password { | |
send $newPass | |
case success next | |
else return ERR_CONFIRM_DIDNT_SUCCEED | |
} | |
} | |
def rootPwd ($username, $oldPass, $newPass) { | |
send "sudo passwd $username" | |
runPwd($username, $oldPass, $newPass) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment