-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransfer2server.sh
executable file
·70 lines (57 loc) · 2.09 KB
/
transfer2server.sh
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
68
69
70
#!/bin/bash
# script: transfer2server.sh
# Aim: transfer data to a SSH server (with available account)
# used to share data with the group of Stein Aerts
### REQUIREMENTS
## SSH access to the KUL server
## rsync installed
# based on Rekin's Janky's command
# SP@NC, 2018_06_04, v 1.0
# defaults matching Stein Aert's server
default_user="u0002316"
default_server="gbw-s-seq07.luna.kuleuven.be"
default_destpath="/media/gbw_shares4/lcb/share/"
usage="## Usage: transfer2server.sh (repeat the command until no extra transfer occurs)
# -i <source file/folder to sync (required)>
# -o <name for the destination folder (required)>
# -u <userID to use for ssh access (default to "${default_user}")>
# -s <destination server address (default to "${default_server}")>
# -p <destination path in which to create the destination folder (default to "${default_destpath}")>
# -h <show this help>"
if [[ ! $@ =~ ^\-.+ ]]; then echo "# This command requires arguments"; echo "${usage}"; exit 1; fi
while getopts "i:o:u:s:p:h" opt; do
case $opt in
i) opt_sourcefolder=${OPTARG} ;;
o) opt_destfolder=${OPTARG} ;;
u) opt_user=${OPTARG} ;;
s) opt_server=${OPTARG} ;;
p) opt_destpath=${OPTARG} ;;
h) echo "${usage}" >&2; exit 0 ;;
\?) echo "Invalid option: -${OPTARG}" >&2; exit 1 ;;
*) echo "# This command requires arguments, try -h" >&2; exit 1 ;;
esac
done
# check if requirements are present
$( hash rsync 2>/dev/null ) || ( echo "# rsync not found in PATH"; exit 1 )
# test if minimal arguments were provided
if [ -z "${opt_sourcefolder}" ]
then
echo "# no source folder provided or folder not existing!"
echo "${usage}"
exit 1
fi
if [ -z "${opt_destfolder}" ]
then
echo "# no destination folder provided!"
echo "${usage}"
exit 1
fi
# or defaults
sshuser=${opt_user:-"${default_user}"}
destserver=${opt_server:-"${default_server}"}
destpath=${opt_destpath:-"${default_destpath}"}
cmd="rsync -avz --rsync-path=\"mkdir -p ${destpath%/}/${opt_destfolder} && rsync \" \
${opt_sourcefolder} \
${sshuser}@${destserver}:${destpath%/}/${opt_destfolder%/}/"
echo "# command: ${cmd}"
eval ${cmd}