-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathssh
executable file
·41 lines (37 loc) · 926 Bytes
/
ssh
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
#!/bin/bash
ssh() {
TMPDIR=~/tmp
case "$(uname -s)" in
CYGWIN_NT* | Linux)
tmp_fifo=$(mktemp -u --suffix=._ssh_fifo)
;;
Darwin)
tmp_fifo=$(/usr/bin/mktemp -u -t ._ssh_fifo)
;;
*)
tmp_fifo=
;;
esac
SSH="/usr/bin/ssh"
SSHPASS=$(command -v sshpass || echo "")
if ! [ -x $SSH ]; then
echo "ssh is not found in PATH!"
exit 1
fi
if [ -x $SSHPASS ] && [ -r ~/.ssh/ssh_pass ]; then
HOST=$1
PASSWORD=$(awk "/$HOST/ {print \$2}" ~/.ssh/ssh_pass)
if ! [ -z $PASSWORD ]; then
SSH="$SSHPASS -p $PASSWORD $SSH"
fi
fi
if [ -z $tmp_fifo ]; then
$SSH -F "$tmp_fifo" "$@"
else
mkfifo "$tmp_fifo"
trap "rm -f $tmp_fifo" EXIT
cat ~/.ssh/config ~/.ssh/config.* >"$tmp_fifo" 2>/dev/null &
$SSH -F "$tmp_fifo" "$@"
fi
}
ssh $*