glasgow rx remote execution of x programs part i posted this a few weeks back but all i got back was an error message pnews dev null permission denied yep dev null had a mode of arrghhh with renewed interest in setting the display variable etc i thought i would post my contribution this perl script is my solution it trys to be intelligent about what it s doing so that you should be able to type rx host domain etc and get a xterm running on host domain etc with all the difficult stuff taken care of in theory this program can do everything you ever wanted to do when you wanted to run a remote command in the background it doesn t even need to be an x program try a rx big machine make for instance for a backgrounded make on the remote big machine for more details and a full list of features read the readme file about lines below all comments welcome duncan bin sh this is a shell archive remove anything before this line then unpack it by saving it into a file and typing sh file to overwrite existing files type sh file c you can also feed this as standard input via unshar or by typing sh file e g if this archive is complete you will see the following message at the end end of archive of contents readme imakefile manifest makefile rx man rx pl wrapped by sinclair dcs gla ac uk on thu apr path bin usr bin usr ucb export path if test f readme a c then echo shar will not clobber existing file readme else echo shar extracting readme characters sed s x readme end of file x x glasgow rx remote execution of x programs version x xcopyright duncan sinclair sinclair dcs gla ac uk x xtrivial to install but there s an imakefile to make it even more trivial x xthe perl script needs some customisation before it is installed just xedit the rx pl file and read the comments once you ve done xthis you can xmkmf then make install install man x xfeatures x x does the right thing for off site remote execution including x setting up display to include domain names and passing x magic cookies or doing the xhost stuff x x allow different remote user name rx l user host x x smart quoting of arguments makes passing wild cards easy x x custom command execution link it to remacs to get a remote x emacs command x x automatic xterm options names the xterm according to hostname x and turns on login shell x x default command is xterm x x propagates x ish env variables to remote session user may x extend the list of variables to pass x x special handling for bourne shell users x x tries to do remote execution from same directory as local x that is it propagates pwd in an intelligent manner x x logs errors in a file x x overall intelligence tm makes reasoned decisions about what x you are trying to do and tries to do the right thing x x written in perl for portability and hackability x xfor more info read the man page or the source x end of file if test ne wc c readme then echo shar readme unpacked with wrong size fi end of readme fi if test f imakefile a c then echo shar will not clobber existing file imakefile else echo shar extracting imakefile characters sed s x imakefile end of file x glasgow rx imakefile x x programs rx x xall programs x xinstall safe x xinstallnamedprog rx pl rx bindir xinstallmanpage rx mandir x xinstall x rm bindir rxterm x ln bindir rx bindir rxterm x xsafe x grep s debug rx pl false x xshar safe x makekit m p x perl pi e s sinclair dcs gla ac uk sinclair dcs gla ac uk part x end of file if test ne wc c imakefile then echo shar imakefile unpacked with wrong size fi end of imakefile fi if test f manifest a c then echo shar will not clobber existing file manifest else echo shar extracting manifest characters sed s x manifest end of file x file name archive description x x readme read me first x imakefile x manifest this shipping list x makefile x rx man x rx pl end of file if test ne wc c manifest then echo shar manifest unpacked with wrong size fi end of manifest fi if test f makefile a c then echo shar will not clobber existing file makefile else echo shar extracting makefile characters sed s x makefile end of file x makefile generated by imake do not edit x xconsortium imake c v rws exp x x the cpp used on this machine replaces all newlines and multiple tabs and x spaces in a macro expansion with a single space imake tries to compensate x for this but is not always successful x x x x makefile generated from imake tmpl and tmp iif a x xconsortium imake tmpl v rws exp x x platform specific parameters may be set in the appropriate vendor cf x configuration files site specific parameters should be set in the file x site def full rebuilds are recommended if any parameters are changed x x if your c preprocessor does not define any unique symbols you will need x to set bootstrapcflags when rebuilding imake usually when doing x make world the first time x x x x site specific configuration parameters that need to come before x the platform specific parameters edit site def to change x x site xconsortium site def v rws exp x x x platform specific configuration parameters edit sun cf to change x x platform xconsortium sun cf v rws exp x x operating system sunos x x xconsortium sunlib rules v rws exp x x x site specific configuration parameters that go after x the platform specific parameters edit site def to change x x site xconsortium site def v rws exp x x shell bin sh x x top x current dir x x ar ar cq x bootstrapcflags x cc gcc fpcc struct return x as as x x compress compress x cpp lib cpp std cpp defines x preprocesscmd gcc fpcc struct return e std cpp defines x install install x ld ld x lint lint x lintlibflag c x lintopts axz x ln ln s x make make x mv mv x cp cp x x ranlib ranlib x ranlibinstflags x x rm rm f x troff psroff x msmacros ms x tbl tbl x eqn eqn x std includes x std cpp defines x std defines x extra load flags x extra libraries x tags ctags x x sharedcodedef dsharedcode x shlibdef dsunshlib x x proto defines x x instpgmflags x x instbinflags m x instuidflags m x instlibflags m x instincflags m x instmanflags m x instdatflags m x instkmemflags g kmem m x x projectroot usr x x x top includes i incroot x x cdebugflags o x ccoptions x x allincludes includes extra includes top includes std includes x alldefines allincludes std defines extra defines proto defines defines x cflags cdebugflags ccoptions alldefines x lintflags lintopts dlint alldefines x x ldlibs sys libraries extra libraries x x ldoptions cdebugflags ccoptions local ldflags l usrlibdir x x ldcombineflags x r x dependflags x x macrofile sun cf x rm cmd rm ckp ln bak bak o core errs a emacs tags tags make log makeout x x imake defines x x irulesrc configdir x imake cmd imake duseinstalled i irulesrc imake defines x x iconfigfiles irulesrc imake tmpl irulesrc imake rules x irulesrc project tmpl irulesrc site def x irulesrc macrofile extra iconfigfiles x x x x window system build parameters x xconsortium project tmpl v rws exp x x x x window system make variables this need to be coordinated with rules x x pathsep x usrlibdir usr x lib x bindir usr x local bin x incroot usr x include x buildincroot top x buildincdir buildincroot x x buildinctop x incdir incroot x x admdir usr adm x libdir usrlibdir x x configdir libdir config x lintlibdir usrlibdir lint x x fontdir libdir fonts x xinitdir libdir xinit x xdmdir libdir xdm x twmdir libdir twm x manpath usr x man x mansourcepath manpath man x mansuffix n x libmansuffix x mandir mansourcepath mansuffix x libmandir mansourcepath libmansuffix x nlsdir libdir nls x pexapidir libdir pex x xapploaddir libdir app defaults x fontcflags t x x instappflags instdatflags x x imake imake x depend makedepend x rgb rgb x x fontc bdftopcf x x mkfontdir mkfontdir x mkdirhier bin sh bindir mkdirhier x x configsrc top config x docutilsrc top doc util x clientsrc top clients x demosrc top demos x libsrc top lib x fontsrc top fonts x includesrc top x x serversrc top server x utilsrc top util x scriptsrc utilsrc scripts x examplesrc top examples x contribsrc top contrib x docsrc top doc x rgbsrc top rgb x dependsrc utilsrc makedepend x imakesrc configsrc x xauthsrc libsrc xau x xlibsrc libsrc x x xmusrc libsrc xmu x toolkitsrc libsrc xt x awidgetsrc libsrc xaw x oldxlibsrc libsrc oldx x xdmcplibsrc libsrc xdmcp x bdftosnfsrc fontsrc bdftosnf x bdftosnfsrc fontsrc clients bdftosnf x bdftopcfsrc fontsrc clients bdftopcf x mkfontdirsrc fontsrc clients mkfontdir x fslibsrc fontsrc lib fs x fontserversrc fontsrc server x extensionsrc top extensions x xilibsrc extensionsrc lib xinput x pexlibsrc extensionsrc lib pexlib x phigslibsrc extensionsrc lib pex x x xconsortium sunlib tmpl v rws exp x xshlibldflags assert pure text xpicflags fpic x x depextensionlib x extensionlib lxext x x depxlib depextensionlib x xlib extensionlib lx x x depxmulib usrlibdir libxmu sa soxmurev x xmulibonly lxmu x xmulib lxmu x x depoldxlib x oldxlib loldx x x depxtoollib usrlibdir libxt sa soxtrev x xtoollib lxt x x depxawlib usrlibdir libxaw sa soxawrev x xawlib lxaw x x depxilib x xilib lxi x x deppexlib x pexlib lpex x x soxlibrev x soxtrev x soxawrev x sooldxrev x soxmurev x soxextrev x soxinputrev x sopexrev x x depxauthlib usrlibdir libxau a x xauthlib lxau x depxdmcplib usrlibdir libxdmcp a x xdmcplib lxdmcp x x depphigslib usrlibdir libphigs a x phigslib lphigs x x depxbsdlib usrlibdir libxbsd a x xbsdlib lxbsd x x lintextensionlib lintlibdir llib lxext ln x lintxlib lintlibdir llib lx ln x lintxmu lintlibdir llib lxmu ln x lintxtool lintlibdir llib lxt ln x lintxaw lintlibdir llib lxaw ln x lintxi lintlibdir llib lxi ln x lintpex lintlibdir llib lpex ln x lintphigs lintlibdir llib lphigs ln x x deplibs depxawlib depxmulib depxtoollib depxlib x x deplibs deplibs x deplibs deplibs x deplibs deplibs x x x imake rules for building libraries programs scripts and data files x rules xconsortium imake rules v rws exp x x x start of imakefile x x glasgow rx imakefile x x programs rx x xall programs x xinstall safe x xinstall rx pl x if d destdir bindir then set x x else set x mkdirhier destdir bindir fi x install c instbinflags rx pl destdir bindir rx x xinstall man rx man x if d destdir mandir then set x x else set x mkdirhier destdir mandir fi x install c instmanflags rx man destdir mandir rx mansuffix x xinstall x rm bindir rxterm x ln bindir rx bindir rxterm x xsafe x grep s debug rx pl false x xshar safe x makekit m p x perl pi e s sinclair dcs gla ac uk sinclair dcs gla ac uk part x x x common rules for all makefiles do not edit x xemptyrule x xclean x rm cmd x xmakefile x if f makefile then set x x rm makefile bak mv makefile makefile bak x else exit fi x imake cmd dtopdir top dcurdir current dir x xtags x tags w ch x tags xw ch tags x xsaber x load alldefines srcs x xosaber x load alldefines objs x x x empty rules for directories that do not have subdirs do not edit x xinstall x echo install in current dir done x xinstall man x echo install man in current dir done x xmakefiles x xincludes x x x dependencies generated by makedepend x end of file if test ne wc c makefile then echo shar makefile unpacked with wrong size fi end of makefile fi if test f rx man a c then echo shar will not clobber existing file rx man else echo shar extracting rx man characters sed s x rx man end of file x th rx march x version x sh name xrx rxterm r remote command xterm anything execution x sh synopsis x b rx x x b l x i username x x i host x x i command x x br x b rxterm x x b l x i username x x i host x x ir args x x sh description xthe x b rx xprogram connect to the specified x i host xand executes the specified x i command xin the background returning immediately to allow the execution xof x programs it copies a number of environmental variables to xthe remote session if you omit x ir command xthen rx will start an xterm on the remote host the x b rxterm xvarient starts a remote xterm on a host and also passes x i args xto the remote xterm as arguments x pp xshell metacharacters which are not quoted are interpreted on the local xmachine while quoted metacharacters are interpreted on the remote xmachine x pp xif the name of the file from which x b rx xis executed is anything other than rx x b rx xtakes this name stripped on a leading r as the command xto run on the remote host using any x i command xparameters as arguments for the remote command x pp xif x b rx xthinks you are using x b xauth xbased x authorisation and you are calling to a off site host or xto a different username it will attempt to copy an authorization xkey to the remote account otherwise it will try to use x b xhost xto grant access to the remote host x sh options x tp x bi l username xuse x i username xas the remote username instead of your local username in the absence xof this option the remote username is the same as your local username x x sh environment xif set the values of path display xenvironment xapplresdir xxfilesearchpath xuserfilesearchpath openwinhome ld library path xand xauthority are exported to the remote program unless the xremote username is different or the remote host is off site in which xcase only display is exported with in all cases any variables named in the xvariable rxenv x pp xthe display variable is tweaked as appropriate to contain as qualified xa hostname as is needed x sh diagnostics x tp x ib command don t recognise my name x b rx xcannot decode the name it has been called under in this case xit prints a warning message and continues as normal x tp x b rx usage rx l username hostname args xthis means it could not decode the arguments given to it x sh author xduncan sinclair sinclair dcs glasgow ac uk july x br xoriginally based on a program with the same name from the x b gwm xdistribution to distinguish this rx from other programs xwith similar names you should refer to this program as the x b glasgow x br rx x sh see also xx rsh xterm xauth xhost gwm x sh bugs x b rx xmakes a number of assumptions about the relationship between the xlocal user and the remote one depending on whether the remote xhost is onsite or not and whether an alternative username was used xor not x pp xin particular if either the locally used shell or the remotely xused shell is the standard bourne shell x b sh xthen strange things are more likely to happen especially when xit s only one of them x pp xsometimes quoting can get messed up x pp xit s too easy to fool the smarts in x b rx xto make it believe something that is not true and fail because of it x pp xwhen x b rx xuses x b xhost xto grant access the x b xhost xcommand may fail silently x pp xif x b rx xtries to send to large a command to the remote machine it will xlikely fail with a parse error from csh if this happens you xwill probably have to reduce the size of the exported environment end of file if test ne wc c rx man then echo shar rx man unpacked with wrong size fi end of rx man fi if test f rx pl a c then echo shar will not clobber existing file rx pl else echo shar extracting rx pl characters sed s x rx pl end of file x usr local bin perl x config change the line above to point to your copy of perl x x glasgow rx version x x copyright duncan sinclair sinclair dcs gla ac uk x x last modified early april x x distribution limited as per the usual mit copyright x x remote execution of x programs based on a script in an old version of gwm x x to install put rx in your bin and make rxterm a link to it x some configuration will be necessary see config comments x x more and more this is less and less like the original x x major hacked to work for our my set up and also partly x re written to work with sh rather than ksh x x maybe i ll turn this into our first zsh script x x looks like it turned into a perl script at some point big improvement x x this code tries to be intelligent in the way it works this means there x are tons of implicit assumptions about the environment it is run in x these assumptions are all valid on the machines i use and in my x environment at the same time i try to make as few assumptions as possible x about the remote machine here s a list of all the more tricky ones x that the remote machine has csh linux x that rshell bin k sh remote shell bin k sh make same x if remote shell sh that path is compatible use csh etc x i pass a cookie to the remote machine if need be but does it x know what to do with a cookie eat it x there must be others x x why am i using csh to run the remote commands simply because it doesn t x interact badly with rsh and hang waiting for a file descriptor to x be closed i d rather use zsh or bash or even perl but they are not x as universal as csh x x xrequire stat pl x x what we called x x argv x argv s x x config x change these variables to be your domain name and a pattern that x will match all variations on your domain name you must include x those leading dots if your hostname includes your domain see x the code further down marked xxx x x dom dcs gla ac uk x dompat dcs gla sgow ac uk x x config x change this to your value of bindir or set the variable to if x you think your users are smarter than that x x xpaths usr x bin x x config x make this the name of your remote shell command x x rsh rsh x x end of config x x some variables we ll no doubt use sometime x x usage argv usage argv l username hostname args n x rshell getpwuid bin sh x home env home getpwuid x xauth env xauthority home xauthority x logf rx log x stuff x debug x x before anything else close stdin this might stop rx hanging x due to rsh weirdness x xclose stdin x x do a l flag x xif argv eq l x shift x user argv die usage x luser l user x shift x x x pick a host any host x x mach argv die usage xshift x x things to think about for the remote machine x x mach s dompat x offsite mach x x where am i seems we can t trust the dumb user to set hostname right x x hostname env hostname hostname current host x hostname hostname current host x hostname s n x x if all your hostnames include your domain comment out the next line x xif offsite hostname hostname dom xxx x x now we know where we are and they are are they different x x diff hostname ne mach x x what is the display going to be x danger heavy regular expressions follow x this needs to be re written to be modular and can so be extended to x support resetting host to unix as required x x display env display x display s dompat x display s unix d d hostname if diff x display s d d dom if offsite x env display display x x here comes the hard bit in sh quote our args x also have to quote quotes to cope with csh braindamage x quotes are quoted thus x so for an arg foo bar we get foo bar x xforeach argv x s g x s x x x so what we doing x xprog x if argv eq rx last prog x if argv eq rxterm x unshift argv ls if diff x unshift argv xterm ls n mach x last prog x x if argv r unshift argv last prog x warn argv don t recognise my name x x x if nothing else become an rxterm x xif argv x unshift argv ls if diff x unshift argv xterm ls n mach x x x some special considerations if we are not ourselves on the other side x xif offsite user x x we want to pass a cookie here x x if e xauth x x this is going to be unsecure as the cookie will appear in a number x of command line args but at least it ll work x this will need enhanced if we ever fix the code above to x set display to when we return to the server x x cookie path path xpaths xauth list display x chop cookie x cooks split cookie x shift cooks x unshift stuff xauth add display cooks if cooks x else x x yuk what a crock i hate doing this x x system xhost mach dev null dev null if diff x x x we really only want to pass a value for display x x vars display split env rxenv x else x x some variables we wish to export x x vars x display x xenvironment x xfilesearchpath x xuserfilesearchpath x xapplresdir x openwinhome x ld library path x manpath for rxman and bourne shell users x xauthority x split env rxenv x x x braindead bourne shell needs to be given a path x we would rather not pass the current path because it might not work x on the destination machine i d rather it was set by the user s x remote shell during the rsh x fortunately all my x programs are in an arch independant place and x so it shouldn t cos a problem locally x we check against rshell because they might be running another shell x differant from their login shell i know sounds weird but it s too x common round here x i ve also included ksh in the brain damage cos i can t see an easy way x to pass throught env env without it being too late we only have x one person who has ksh as a login shell anyway x oh yeah we are assuming that if it s bourne shell here then it s x bourne shell there much more important than this is that it it isnt x bourne shell here it better not be bourne shell there x x if rshell m k sh push vars path x x x validate pwd routine x xsub validate pwd x local pwdstats dotstats x local pwd x x unless defined pwd return undef x unless dotstats stat return undef x unless pwdstats stat pwd return undef x if pwdstats st dev dotstats st dev x pwdstats st ino dotstats st ino return undef x pwd x x x try and find a nice valid pwd x xpresent x if pwd env pwd x foopwd pwd x foopwd s tmp mnt export x pwd validate pwd foopwd validate pwd pwd x x unless pwd x chop pwd pwd x foopwd pwd x foopwd s tmp mnt export x pwd validate pwd foopwd validate pwd pwd home x x x pwd s x x try to find somewhere nice to live on the other side x xunless offsite x unshift stuff test d pwd cd pwd x x x start building the full command x xforeach var vars x val env var x unshift stuff setenv var val x x x some commands to do on the other side x xunshift stuff set nonomatch only if we are using csh x x build the remote command x x remote umask join stuff argv dev null logf x remote s g x remote remote x x build the arg list for the exec x x comm rsh luser mach csh fc remote x x do it x xif debug x print comm n x else x exec comm x x x rsh doesn t return any indication of how it went over x on the other side but that s ok cos we aint going to x wait around to see what happened x xexit x x the end end of file if test ne wc c rx pl then echo shar rx pl unpacked with wrong size fi chmod x rx pl end of rx pl fi echo shar end of archive of cp dev null ark isdone missing for i in do if test f ark i isdone then missing missing i fi done if test missing then echo you have the archive rm f ark isdone else echo you still need to unpack the following archives echo missing fi end of shell archive exit duncan sinclair sinclair dcs gla ac uk sinclair uk ac gla dcs would the real unix operating system please stand up
