-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathssh-executed-with-command
More file actions
executable file
·56 lines (47 loc) · 1.32 KB
/
ssh-executed-with-command
File metadata and controls
executable file
·56 lines (47 loc) · 1.32 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
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
# This script is meant to be used from within ssh_config.
#
# It fixes weird behavior of SSH where it returns error when executing
# command from command line while RemoteCommand was used in configuration file
# for this host, like this:
#
# Host pirx
# RemoteCommand fish
# RequestTTY yes
#
# Such configuration results in error when executing remote command:
# #> ssh pirx ls śro, 10 cze 2020, 11:26:07
# Cannot execute command-line and remote command.
#
# To fix this behavior simply add the following to your .ssh/config or /etc/ssh/ssh_config file:
#
# Match exec "ssh-executed-with-command"
# RemoteCommand none
# RequestTTY auto
#
if [[ -z "$1" ]]; then
pid=$PPID
while [[ "$(cat "/proc/$pid/comm")" != "ssh" ]]; do
pid="$(ps -o ppid= $pid)"
pid="${pid//[[:blank:]]/}"
if (( pid == 0 )); then
exit 0
fi
done
exec xargs -0 "$0" < /proc/$pid/cmdline
fi
shift
unrecognizedOptions=0
while getopts 46AaCfGgKkMNnqsTtVvXxYyB:b:c:D:E:e:F:I:i:J:L:l:m:O:o:p:Q:R:S:W:w: FLAG; do
case $FLAG in
\?|:)
(( unrecognizedOptions++ ))
;;
*)
;;
esac
done
if (( unrecognizedOptions > 0 )) || (( $# > 1 )); then
exit 0
fi
exit 1