-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssh.sh
executable file
·53 lines (42 loc) · 1.13 KB
/
ssh.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
#!/usr/bin/env bash
d=`dirname $0`
min_params_count="1"
max_params_count="2"
if [ $# -lt $min_params_count ]
then
echo "Needs params, like:"
echo "$0 <name> [sshf mount path]"
exit 1
elif [ $# -gt $max_params_count ]
then
echo "Needs params, like:"
echo "$0 <name> [sshf mount path]"
exit 2
fi
name=$1
ssh_conf_path="$d/../.ssh.conf"
while read line
do
ssh_name=`expr match "$line" '\([^ \#]*\)[ ]*[^ ]*[ ]*[^ ]*[ ]*[^ ]*[ ]*[^ ]*'`
host=`expr match "$line" '[^ \#]*[ ]*\([^ ]*\)[ ]*[^ ]*[ ]*[^ ]*[ ]*[^ ]*'`
path=`expr match "$line" '[^ \#]*[ ]*[^ ]*[ ]*\([^ ]*\)[ ]*[^ ]*[ ]*[^ ]*'`
login=`expr match "$line" '[^ \#]*[ ]*[^ ]*[ ]*[^ ]*[ ]*\([^ ]*\)[ ]*[^ ]*'`
pass=`expr match "$line" '[^ \#]*[ ]*[^ ]*[ ]*[^ ]*[ ]*[^ ]*[ ]*\([^ ]*\)'`
if [ "$ssh_name" = "$name" ]; then
if [ $# -eq 1 ]; then
echo "ssh $login@$host"
echo " $path"
echo " $pass"
elif [ $# -eq 2 ]; then
if [ -d $2 ]; then
echo " $pass"
sshfs $login@$host:$path $2
else
echo "Error $2 not a dir or not exists!"
exit 1
fi
fi
exit 0
fi
done < $ssh_conf_path
echo "Not Found!"