-
Notifications
You must be signed in to change notification settings - Fork 0
/
sshp
42 lines (34 loc) · 782 Bytes
/
sshp
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
#!/bin/bash
RC_ERR_NO_HOST=11
RC_ERR_NO_PASSWORD=21
RC_ERR_NO_SSHPASS=31
RC_SUCCESS=0
#line format should be "host-alias password server"
pass_path=~/.ssh/sshp_pass
host=$1
# arguments
if [ -z $host ]; then
echo "ERR_NO_HOST, please input host."
exit $RC_ERR_NO_HOST
fi
# read file
rec=`grep "$host " $pass_path | cut -d' ' -f 2,3`
if [ -z "$rec" ]; then
echo "ERR_NO_PASSWORD, please record password first. file path $pass_path"
exit $RC_ERR_NO_PASSWORD
fi
if [ 1 -eq ${#rec[*]} ]; then
OLD_IFS="$IFS"
IFS=" "
conf=($rec)
IFS="$OLD_IFS"
else
conf=($rec)
fi
path=`which sshpass`
if [ -z $path ]; then
echo "ERR_NO_SSHPASS, must install sshpass first"
exit $RC_ERR_NO_SSHPASS
fi
$path -p ${conf[0]} ssh ${conf[1]}
exit $RC_SUCCESS