#!/usr/bin/bash # assign the environment to a a=`env |sed -n -e '/^!::=/d' -e 's,$,_EOL_,g' -e 's,'\'',_APOS_,g' -e 's/\([A-Za-z0-9_][A-Za-z0-9_]*\)=/'\'';\1='\''/' -e '/./p'` rm -f /tmp/env.$$ echo "#!`which bash`" > /tmp/env.$$ chmod 755 /tmp/env.$$ userarg="Administrator" options=":lc:fmps:" repeat=1; while [ $repeat -ne 0 ] ; do getopts $options arg if [ $? -ne 0 ] ; then arg="$1" OPTIND=2 fi case "x$arg" in xl | x- | x--login) loginarg=1 if [ -z "$shellarg" ] ; then shellarg=`which bash` fi ;; xc | x--command | x--command) commandarg="$OPTARG" ;; x--command=*) commandarg="${arg##--command=}" ;; xf | x--fast ) fastarg=1 if [ -z "$shellarg" ] ; then shellarg=`which tcsh` fi if [ -z "$shellarg" ] ; then shellarg=`which csh` fi ;; xm | xp | x--preserve-environment) echo $a|sed -e 's,^'\'';,,' -e 's,_EOL_$,'\'',' -e 's,_EOL_ '\'';,'\'';\ ,g' -e "s,_APOS_,'\\'',g" -e 's,_EOL_ ,\ ,g' >> /tmp/env.$$ env|sed -n -e 's,\([A-Za-z0-9_][A-Za-z0-9_]*\)=.*,export \1;,p' >> /tmp/env.$$ preservearg=1 ;; xs ) shellarg="$OPTARG" ;; x--shell) shellarg="$OPTARG" OPTIND=3 ;; x--shell=*) shellarg="${arg##--shell=}" ;; *) repeat=0 OPTIND=1 ;; esac while [ $OPTIND -gt 1 ] ; do shift OPTIND=`expr $OPTIND - 1` done done if [ -n "$1" ] ; then userarg="$1" shift fi if [ -z "$shellarg" ] ; then shellarg=`which bash` fi if [ -n "$commandarg" ] ; then echo "exec \"$shellarg\" $fastarg $loginarg -c \"$commandarg\"" >>/tmp/env.$$ elif [ -n "$*" ] ; then echo "exec \"$shellarg\" $fastarg $loginarg -c \"$@\"" >>/tmp/env.$$ else echo "exec \"$shellarg\" $fastarg $loginarg -i -s" >>/tmp/env.$$ fi echo "cd '`pwd`'">>/tmp/env.$$ trap "rm -f /tmp/env.$$" EXIT ssh -t -l "$userarg" localhost /tmp/env.$$ exit $?