-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssh-wrapper.sh
More file actions
executable file
·43 lines (38 loc) · 1.03 KB
/
ssh-wrapper.sh
File metadata and controls
executable file
·43 lines (38 loc) · 1.03 KB
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
#!/bin/bash
sshcommand="/usr/bin/ssh"
options=""
host=""
remotecommand=""
hostsfile="myhosts"
wasoption=0
for arg in "$@"; do
if [ -z "$host" ]; then
echo "$arg" | grep "^-" > /dev/null
if [ $? -eq 0 ]; then
options="$options $arg"
wasoption=1
else
if [ $wasoption -ne 0 ]; then
options="$options $arg"
wasoption=0
else
host="$arg"
fi
fi
else
remotecommand="$remotecommand $arg"
fi
done
echo "$host" | grep "@" > /dev/null
if [ $? -eq 0 ]; then
user=`echo "$host" | cut -d"@" -f 1`
host=`echo "$host" | cut -d"@" -f 2`
fi
ip=`grep -i "$host" $hostsfile | cut -d";" -f 2`
if [ -n "$ip" ]; then
host=$ip
fi
if [ -n "$user" ]; then
host="$user@$host"
fi
$sshcommand $options $host $remotecommand