summaryrefslogtreecommitdiff
path: root/linuxinstall/shell/check_userpass.sh
diff options
context:
space:
mode:
authorchenjinsong <[email protected]>2018-09-27 16:11:54 +0800
committerchenjinsong <[email protected]>2018-09-27 16:11:54 +0800
commit56d71f261a8bd6031e47e2bf80867049a2aa13da (patch)
treef09257b2143782a333a9eda3395137837d9bdad1 /linuxinstall/shell/check_userpass.sh
initial commit
Diffstat (limited to 'linuxinstall/shell/check_userpass.sh')
-rw-r--r--linuxinstall/shell/check_userpass.sh47
1 files changed, 47 insertions, 0 deletions
diff --git a/linuxinstall/shell/check_userpass.sh b/linuxinstall/shell/check_userpass.sh
new file mode 100644
index 0000000..6e6dc7d
--- /dev/null
+++ b/linuxinstall/shell/check_userpass.sh
@@ -0,0 +1,47 @@
+#!/usr/bin/expect
+
+if {$argc!=3} {
+ send_user "usage: check_userpass.sh ip name password\n"
+ exit 1
+}
+
+set host [lindex $argv 0]
+set user [lindex $argv 1]
+set pass [lindex $argv 2]
+
+set isSend 0
+spawn ssh -t "${user}@${host}"
+
+while 1 {
+ expect {
+ "* (yes/no)*" {send "yes\r"}
+ "* ����*" {
+ send "${pass}\r"
+ set isSend 1
+ }
+ "* password:*" {
+ send "${pass}\r"
+ set isSend 1
+ }
+ "Permission denied" {
+ send_user "Not allowed\n"
+ exit 1
+ }
+ "*~]" {
+ send_user "OK\n"
+ send "exit\r"
+ exit 0
+ }
+ "Last login:*" {
+ send_user "OK\n"
+ send "exit\r"
+ exit 0
+ }
+ default {
+ send_user "error\n"
+ exit 2
+ }
+ }
+}
+
+