blob: 31aca20060e2d4c2672bf90cb64dcea0f44200c6 (
plain)
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
|
#! /bin/sh
# usage: services [user@]hostname[:port]
# environment:
# services_identity_file path to ssh(1) identity_file
set -euf
user=services
hostname=${1-localhost}
port=1337
options="${options+$options }-o ControlMaster=no"
if test -n "${services_identity_file-}"; then
options="${options+$options }-i $services_identity_file"
fi
if echo $hostname | grep -q @; then
user=`echo $hostname | cut -d@ -f1`
hostname=`echo $hostname | cut -d@ -f2`
fi
if echo $hostname | grep -q :; then
port=`echo $hostname | cut -d: -f2`
hostname=`echo $hostname | cut -d: -f1`
fi
exec 3>&1
{
set +e
ssh $options $user@$hostname -p $port
echo "# Exit:$?" >&2
} 2>&1 1>&3 | {
err="`cat`"
code=`echo "$err" | sed -n 's/^# Exit:\([0-9]\+\)/\1/p'`
echo "$err" | sed '
/^Connection to '$hostname' closed/d
/^Shared connection to '$hostname' closed/d
/^# Exit:/d
' >&2
exit $code
}
|