-
Notifications
You must be signed in to change notification settings - Fork 7
/
.from_here_to_there.sh
executable file
·83 lines (81 loc) · 1.58 KB
/
.from_here_to_there.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
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
# Usage::
# DEST=$IP_OR_DOMAIN sh ~/archives/carstino/.from_here_to_there.sh $1 $2
if [ "$SSH_USER" ]; then
HOST=$SSH_USER@$DEST
else
if [ "$USER" = "root" ]; then
HOST=$DEST
else
HOST=root@$DEST
fi
fi
if [ $1 ]; then
cmd="scp -r"
if [ $PRI ]; then
cmd="$cmd -i $PRI"
fi
if [ $PORT ]; then
cmd="$cmd -P $PORT"
fi
if [ $2 ]; then
echo $1 |grep -q '/'
if [ $? -eq 0 ]; then
cmd="$cmd $HOST:$1 $2"
else
cmd="$cmd $HOST:~/$1 $2"
fi
else
if [ "$SCP_DIR" ]; then
echo $SCP_DIR |grep -q '/'
if [ $? -eq 0 ]; then
cmd="$cmd $1 $HOST:$SCP_DIR"
else
cmd="$cmd $1 $HOST:~/$SCP_DIR"
fi
else
cmd="$cmd $1 $HOST:~/"
fi
fi
else
cmd="ssh"
if [ $T_HOST ]; then
cmd="$cmd -t $T_HOST"
fi
if [ $PRI ]; then
cmd="$cmd -i $PRI"
fi
if [ $PORT ]; then
cmd="$cmd -p $PORT"
fi
cmd="$cmd $HOST"
fi
if [ "$SSH_PASS" ]; then
if [ -f /usr/bin/expect ]; then
EXP_FILE=".do_ssh.exp"
if [ $1 ]; then
EXP_FILE=".do_scp.exp"
fi
if [ -f ~/archives/carstino/$EXP_FILE ]; then
EXP_FILE="~/archives/carstino/$EXP_FILE"
elif [ -f ~/$EXP_FILE ]; then
EXP_FILE="~/$EXP_FILE"
elif [ -f $EXP_FILE ]; then
EXP_FILE="./$EXP_FILE"
else
EXP_FILE=""
fi
if [ "$EXP_FILE" ]; then
cmd="expect $EXP_FILE '$cmd' $SSH_PASS"
else
echo "--> $cmd"
echo "$SSH_PASS"
fi
else
echo 'WARNING: /usr/bin/expect not exist. Run `which expect` to check it.'
echo $SSH_PASS
fi
else
echo "--> $cmd"
fi
sh -c "$cmd"