-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpconsole.sh.in
160 lines (139 loc) · 3.49 KB
/
pconsole.sh.in
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#! /bin/sh
#
# pconsole WJ101
# Copyright (C) 2001 Walter de Jong <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# pconsole.sh WJ101
#
# Open windows and have pconsole attach to them
# NOTE: ssh is weird and it doesn't work without the ssh.sh wrapper script
#
# Change to "1" or "yes" to enable debugging
DEBUG=""
if [ ! -z "${DEBUG}" ]
then
set -x
fi
PATH=/bin:/usr/bin:/usr/bin/X11:/usr/openwin/bin:/usr/local/bin:/usr/bsd:/usr/share/bin:/opt/bin:/etc:/usr/etc
prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
#
# options: you can overrule these by setting them in your environment
#
if [ -z "${P_TERM}" ]
then
P_TERM=xterm
fi
if [ -z "${P_TERM_OPTIONS}" ]
then
P_TERM_OPTIONS="-geometry 40x12 -fn 5x7"
fi
if [ -z "${P_CONNECT_CMD}" ]
then
P_CONNECT_CMD="${bindir}/ssh.sh"
fi
if [ -z "${P_CONSOLE_OPTIONS}" ]
then
P_CONSOLE_OPTIONS="-geometry 60x12"
fi
#
# get tty
# Mind that ps output may be platform dependent
# If so, you have to adjust this function
#
# What it does is get the tty that has the parent pid equal to the pid of
# the xterm we launched
#
get_tty() {
if [ ! -z "${DEBUG}" ]
then
set -x
fi
PS_PERSONALITY=posix # may be needed for GNU ps :P
ps -ef 2>/dev/null | awk '{ print $3 " " $6 }' | egrep "^$1" | awk '{ print $2 }'
}
#
# main
#
if [ -z "$1" ]
then
PROG=`basename $0`
echo "usage: ${PROG}" '<hostname>[:port] [...]'
exit 1
fi
THIS_TTY=`tty`
#
# run this in a sub-shell so the user gets the prompt back
# We start all windows, give them some time to initialize, and then get all
# ttys that have those (parent) pids
# Then we combine the host#tty pairs, and give that to the pconsole binary
#
(
if [ ! -z "${DEBUG}" ]
then
set -x
fi
HOSTLIST="$*"
for HOST in ${HOSTLIST}
do
# get optional port number
PORT=`echo "${HOST}" | cut -d: -f2`
HOSTNAME=`echo "${HOST}" | cut -d: -f1`
if [ "${PORT}" = "${HOSTNAME}" ];
then
PORT=''
fi
# open windows
${P_TERM} ${P_TERM_OPTIONS} -title "pconsole: ${HOST}" -name "pconsole: ${HOST}" -e ${P_CONNECT_CMD} ${HOSTNAME} ${PORT} &
PID=$!
PIDLIST="${PIDLIST} ${PID}"
done
for PID in ${PIDLIST}
do
TTY=''
while [ -z "${TTY}" ]
do
TTY=`get_tty "${PID}"`
# sometimes xterm is too slow forking off, and get_tty will give the same
# tty as we started from. This would be incorrect, and if so, we try again
if [ "/dev/${TTY}" = "${THIS_TTY}" ];
then
TTY=''
sleep 1
fi
done
HOST=`echo ${HOSTLIST} | cut -d\ -f1`
HOSTLIST=`echo ${HOSTLIST} | cut -d\ -f2-999`
if [ ! -z "${HOST}" ]
then
TTYS="${TTYS} ${HOST}#/dev/${TTY}"
else
TTYS="${TTYS} /dev/${TTY}"
fi
done
# start pconsole
${P_TERM} ${P_CONSOLE_OPTIONS} -title pconsole -name pconsole -e "${bindir}/pconsole" ${TTYS}
# terminate all open windows
if [ ! -z "${PIDLIST}" ]
then
kill ${PIDLIST} >/dev/null 2>&1
fi
exit 0
) &
exit 0
# EOB