-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgotocmd
More file actions
executable file
·45 lines (34 loc) · 750 Bytes
/
gotocmd
File metadata and controls
executable file
·45 lines (34 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
# Author: casheywen@qq.com
if [[ $# -lt 2 ]]
then
echo "Usage: $0 ipfile cmd"
exit
fi
MACHINE_LIST="$1"
CMD="$2"
TMP="/tmp/login${RANDOM}"
read IP USER PASSWORD PORT < "${MACHINE_LIST}"
if [[ ${?} -ne 0 || -z "${PORT}" ]]
then
echo "${0}: ${MACHINE_LIST} does not exist or format error" >&2
exit 1
fi
cat << EOF > "${TMP}"
set timeout 8
spawn -noecho ssh ${USER}@${IP} -p${PORT} -o StrictHostKeyChecking=no "${CMD}"
while (1) {
expect {
"yes/no)?" { send "yes\r";puts "yes" }
"assword:" { send "${PASSWORD}\r"; break }
timeout { puts "${IP} time out" ;exit 2; break }
}
}
expect eof
catch wait result
exit [lindex \$result 3]
EOF
expect "${TMP}"
RET=$?
rm "${TMP}"
exit ${RET}