-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpullfile
More file actions
executable file
·46 lines (35 loc) · 776 Bytes
/
pullfile
File metadata and controls
executable file
·46 lines (35 loc) · 776 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
46
#!/bin/bash
# Author: casheywen@qq.com
if [[ $# -lt 3 ]]
then
echo "Usage: $0 ipfile src_path dst_path"
exit
fi
MACHINE_LIST="$1"
SRC_PATH="$2"
DST_PATH="$3"
TMP="/tmp/pull${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 scp -P${PORT} -r "${USER}@${IP}:${SRC_PATH}" "${DST_PATH}"
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}