#!/bin/bash # # Remotty, remote host script, Copyright (C) Jan-Mar 2006, Jeffrey S. Dutky # version 1.0, 16 March 2006 # # THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND, WITHOUT # EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR # PURPOSE. IN NO EVENT SHALL THE AUTHOR OF THIS SOFTWARE BE LIABLE FOR DAMAGES # RESULTING FROM THE USE OF THIS SOFTWARE. # # The remotty script creates a session on a remote machine running in an xterm. # The colors of the xterm are set based on entries in the .hostcolorsrc file. # The session, by default, uses SSH to connect to the remote system, but either # telnet or rsh can be used by specifying the -t or -r flags. The initial # geometry of the xterm window can be set with the -g flag (the default is # 80x35). The program can be run in a debug mode with the -d flag, and the # resulting xterm command can be printed (echoed), rather than executed, with # the -e flag. The names of all the hosts in the .hostcolorsrc file can be # printed with the -h flag. The -n flag can be used to specify that more than # one terminal window should be opened to the specified host. # # preset program variables # VERSION="1.0" VERDATE="16 March 2006" COPYRIGHT="2006, Jeffrey S. Dutky" RHOST="" # hostname specified on the command line FHOST="" # hostname in .hostcolorsrc file host block that matches RHOST MHOST="" # hostname in .hostcolorsrc file host block used for lookups PRG="ssh -X" # program to use to contact host (defaults to ssh) BGC=white # background color FGC=black # foreground color CSR=black # cursor color HOSTS="" # flag to dump hostnames from .hostcolorsrc file DEBUG="" # debug mode, print lots of stuff as the program runs ECHO="" # echo mode, only echo the resulting xterm command, don't run it TITLE="" # title to use for xterm window EXE="" # executable stuff to put before command NUM=1 # number of terminal windows to open to the host GEOM="-geometry 80x35" # default window geometry # # process command line parameters # while [ "$1" != "" ] do case "$1" in "-r") PRG="rsh" ;; "-t") PRG="telnet" ;; "-h") HOSTS=yes ;; "-g") GEOM="-geometry $2" shift ;; "-n") NUM=$2 shift ;; "-d") DEBUG=yes ;; "-e") ECHO=yes ;; "-x") set -x ;; "-v"|"--version") echo "remotty, version $VERSION, $VERDATE" echo "Copyright (C) $COPYRIGHT" echo "download from http://members.bellatlantic.net/~dutky" exit ;; *) RHOST="$1" ;; esac shift done # display list of hosts, if requested if [ "$HOSTS" == "yes" ] then if [ "$DEBUG" == "yes" ] then echo "display list of hosts" fi while read X Y do if [ "$X" == "host" ] then echo "$Y" fi done < ~/.hostcolorsrc exit fi # # check to see that a host was specified, if not, show the usage message # if [ "$DEBUG" == "yes" ] then echo "check that a host was specified" fi if [ "$RHOST" == "" ] then echo "No host specified. Usage:" echo echo " `basename $0` [-d] [-e] [-r] [-t] [-x] [-n num] [-g geometry] hostname" echo echo " -d debug output" echo " -e echo command (don't execute)" echo " -g specify XTerm geometry" echo " -n specify how many terminal windows to open" echo " -r use rsh instead of ssh" echo " -t use telnet instead of ssh" echo " -x trace output (bash 'set -x')" echo echo " `basename $0` -h" echo echo " -h list hostnames from configuration file (~/.hostcolorsrc)" echo echo "version $VERSION, Copyright (C) $COPYRIGHT, dutky@bellatlantic.net" echo "you can get this program at http://members.bellatlantic.net/~dutky" exit fi # # load colors for specified host from the ~/.hostcolorsrc file # if [ "$DEBUG" == "yes" ] then echo "load colors for the host $RHOST" fi while read -a ELEM do if [ "${ELEM[0]}" == "host" ] then # see if the requested remote host is in the host name list I=1 while [ "${ELEM[I]}" != "" ] do if [ "$DEBUG" == "yes" ] then echo -n " is \"${ELEM[I]}\" = \"$RHOST\"? " fi if [ "${ELEM[I]}" == "$RHOST" ] then if [ "$DEBUG" == "yes" ] then echo "yes" fi FHOST="${ELEM[I]}" # host name that matches requested host MHOST="${ELEM[1]}" # host name that can be used for lookups else if [ "$DEBUG" == "yes" ] then echo "no" fi fi I=$((I+1)) done continue fi if [ "$FHOST" == "$RHOST" ] then # if the current host block matches the requested host, use the values if [ "$DEBUG" == "yes" ] then echo " evaluate \"${ELEM[*]}\"" fi case "${ELEM[0]}" in "fgc") FGC="${ELEM[1]}" ;; "bgc") BGC="${ELEM[1]}" ;; "csr") CSR="${ELEM[1]}" ;; "title") if [ "$TITLE" == "" ] then TITLE=${ELEM[1]} N=2 while [ "${ELEM[N]}" != "" ] do TITLE="$TITLE ${ELEM[N]}" N=$((N+1)) done fi ;; "prg") PRG=${ELEM[1]} N=2 while [ "${ELEM[N]}" != "" ] do PRG="$PRG ${ELEM[N]}" N=$((N+1)) done ;; "noprg") PRG="" ;; "exe") EXE=${ELEM[1]} N=2 while [ "${ELEM[N]}" != "" ] do EXE="$EXE ${ELEM[N]}" N=$((N+1)) done EXE="$EXE;" ;; "end") FHOST="" ;; esac fi done < ~/.hostcolorsrc # # launch a copy of xterm in the background # if [ "$DEBUG" == "yes" ] then echo "TITLE='$TITLE'" fi if [ "$TITLE" == "" ] then TITLE=$RHOST fi if [ "$DEBUG" == "yes" ] then echo "PRG='$PRG'" fi if [ "$PRG" == "" ] then CMD="${EXE}xterm $GEOM -T '$TITLE' -bc -sb -sl 1000 -cr $CSR -fg $FGC -bg $BGC" else CMD="${EXE}xterm $GEOM -T '$TITLE' -bc -sb -sl 1000 -cr $CSR -fg $FGC -bg $BGC -e $PRG $MHOST" fi if [ "$ECHO" == "yes" ] then if [ $NUM -gt 1 ] then echo "$NUM copies of:" echo -n " " fi echo "$CMD" else N=0 while [ $N -lt $NUM ] do eval "$CMD" & N=$((N+1)) done fi