#! /bin/sh # # @(#) Revision : v1.0 # # Copyright (C) 2001 Walter de Jong # pconsole-gnome for opensolaris is derived from pconsole.sh # # # 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-gnome WJ101 # # Open windows and have pconsole attach to them # # Change to "1" or "yes" to enable debugging DEBUG="" CommandOpts="thd" trap "wait_clean_and_exit 1" 1 2 3 15 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=/usr exec_prefix=${prefix} bindir=${exec_prefix}/bin tmpdir=/tmp # # options: you can overrule these by setting them in your environment # if [ -z "${G_TERM}" ] then G_TERM=gnome-terminal fi if [ -z "${G_TERM_OPTIONS}" ] then G_TERM_OPTIONS="--hide-menubar" fi if [ -z "${P_CONNECT_CMD}" ] then P_CONNECT_CMD="${bindir}/ssh" fi if [ -z "${P_CONSOLE_OPTIONS}" ] then P_CONSOLE_OPTIONS="--hide-menubar --geometry 80x5" fi # # get tty # Mind that ps output may be platform dependent # If so, you have to adjust this function # function 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 $2 " " $6 }' | egrep "^$1" | awk '{ print $2 }' } usage() { PROG=`basename $0` echo "usage: ${PROG} ${CommandUsage} '[user@][:port] [...]'" echo " -h => help" echo " -d => Debug" echo " -t => Run pconsole in the current terminal" } wait_clean_and_exit() { if [ ! -z "${DEBUG}" ] then set -x fi if [ -z $P_CONNECT_LIST ] then exit $1 else cd ${tmpdir} for file in `ls $P_CONNECT_LIST` do if [ -f $file ] then PID=`pgrep ${file}` while [ ! -z $PID ] do PID=`pgrep ${file}` sleep 2 done rm $file fi done exit $1 fi } # # main # while getopts ${CommandOpts} option do case ${option} in t) CTER=1;; d) DEBUG=1;; h) HELP=1;; ?) usage exit 2 ;; esac done shift $(($OPTIND - 1)) HOSTLIST="$*" P_CONNECT_LIST='' PCONNECT_NB=0 if [ -z "$1" -o $HELP ] then usage exit 1 fi if [ ! -z "${DEBUG}" ] then set -x fi ${bindir}/pconsole-bin -t if [ $? -ne 0 ] then exit 1 fi for HOST in ${HOSTLIST} do # get optional port number USER=`echo "${HOST}" | cut -d@ -f1` CONN=`echo "${HOST}" | cut -d@ -f2` if [ "${USER}" = "${CONN}" ]; then USER=`who am i|nawk '{print $1}'` fi PORT=`echo "${CONN}" | cut -d: -f2` HOSTNAME=`echo "${CONN}" | cut -d: -f1` if [ "${PORT}" = "${HOSTNAME}" ]; then PORT="22" fi P_CONNECT_CMD_NB="PCMD_$$_${PCONNECT_NB}" P_CONNECT_LIST="$P_CONNECT_LIST $P_CONNECT_CMD_NB" cp -p ${P_CONNECT_CMD} ${tmpdir}/${P_CONNECT_CMD_NB} ${G_TERM} ${G_TERM_OPTIONS} --title "pconsole: ${HOST}" --execute ${tmpdir}/${P_CONNECT_CMD_NB} -l ${USER} -p ${PORT} ${HOSTNAME} & PID='' while [ -z $PID ] do PID=`pgrep ${P_CONNECT_CMD_NB}` sleep 1 done # Disable re-use of P_CONNECT_CMD_NB chmod -x ${tmpdir}/${P_CONNECT_CMD_NB} # get P_CONNECT_CMD_NB tty TTY='' TTY=`get_tty "${PID}"` if [ $TTY == "?" ] then echo "ERROR: Unable to get tty for $PID" exit 1 fi TTYS="${TTYS} /dev/${TTY}" PCONNECT_NB=`expr $PCONNECT_NB + 1` done # test pconsole - need to be root, or program is setuid if [ ${CTER} ] then ${bindir}/pconsole-bin ${TTYS} else ${G_TERM} ${P_CONSOLE_OPTIONS} --title pconsole --execute ${bindir}/pconsole-bin ${TTYS} fi wait_clean_and_exit 0