Created
October 18, 2017 05:57
-
-
Save lisp-ceo/7f61ea342f46b12cc92fe12de081bdac to your computer and use it in GitHub Desktop.
Script to update default password on linux-academy servers to something useful
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
update_server_password: | |
./update_la_pwd.exp $LI_IP $PASSWORD |
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
#!/usr/bin/env expect -f | |
## Script to update default password on linux-academy servers to something useful | |
## References | |
### http://www.admin-magazine.com/Articles/Automating-with-Expect-Scripts | |
### https://www.pantz.org/software/expect/expect_examples_and_tips.html | |
### http://wiki.tcl.tk/11583 | |
set send_human {.1 .3 1 .05 2} | |
set strace 4 | |
set hostname [lindex $argv 0] | |
set password [lindex $argv 1] | |
if {[llength $argv] != 2} { | |
send_user "Usage: scriptname \'hostname\' \'password\'\n" | |
exit 1 | |
} | |
spawn ssh -t user@$hostname | |
expect { | |
-re ".*Are you sure you want to continue.*" { | |
send "yes\r" | |
} | |
default { | |
send_user "Failed match on auth" | |
exit 1 | |
} | |
} | |
expect { | |
default { | |
send -h "123456\r" | |
} | |
} | |
expect -re ".*" {} | |
expect -re ".*" {} | |
expect -re ".*" {} | |
expect -re ".*" {} | |
expect -re ".*" {} | |
expect -re ".*" {} | |
expect { | |
"(current) UNIX password:" { | |
send "123456\r" | |
} | |
} | |
expect { | |
"New password:" { | |
send "$password\r" | |
} | |
} | |
expect { | |
"Retype new password:" { | |
send "$password\r" | |
} | |
} | |
expect { | |
"passwd: all authentication tokens updated successfully." { | |
send_user "Updated password to be $password" | |
exit 0 | |
} | |
default { | |
send_user "Failed. You messed up somewhere. Buh-bye!" | |
exit 1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment