-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathautoscp.sh
More file actions
executable file
·70 lines (57 loc) · 1.85 KB
/
autoscp.sh
File metadata and controls
executable file
·70 lines (57 loc) · 1.85 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
# Title : auto copy files to remote
# Date : Sat May 2 14:54:10 CST 2015
# Author: andychen ([email protected])
#
# Usage :
# ./autoscp.sh file 1 #copy to remote (file 不能有文件的/,而且要和autoscp.sh在同级目录)
# ./autoscp.sh file 0 #copy to local
USER=user
PASS=passwd
HOST=remote_ip
FILE=${1}
TYPE=${2}
REMOTE_PATH=/root/
LOCAL_PATH=~/scp/
# check
if [ $# != 2 ];then
echo "+-----------------------------------------------------+"
echo "| error! |"
echo "|-----------------------------------------------------|"
echo "| |"
echo "| Usage: |"
echo "| ./autoscp.sh file 1 |"
echo "| or |"
echo "| ./autoscp.sh file 0 |"
echo "+-----------------------------------------------------+"
exit 0
fi
if [ ${TYPE} != 1 ]&&[ ${TYPE} != 0 ];then
echo "+-----------------------------------------------------+"
echo "| you input this type is error! |"
echo "+-----------------------------------------------------+"
exit 0
fi
if [ ${TYPE} = 1 ]&&[ ! -e ${FILE} ];then
echo "+-----------------------------------------------------+"
echo "| you input this file is not found! |"
echo "+-----------------------------------------------------+"
exit 0
fi
# copy to remote
if [ ${TYPE} = 1 ];then
if [ -d ${FILE} ];then
tar -zvcf ${FILE}.tar.gz ${FILE}
FILE=${FILE}.tar.gz
fi
scp ${FILE} ${USER}@${HOST}:${REMOTE_PATH}
ssh ${USER}@${HOST} "cd ~; ./untar.sh ${FILE}"
rm -f ./${FILE}
exit 0
fi
# copy to local
if [ ${TYPE} = 0 ];then
mkdir -p ${LOCAL_PATH}
scp ${USER}@${HOST}:${REMOTE_PATH}${FILE} ${LOCAL_PATH}
exit 0
fi