home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!europa.eng.gtefsd.com!emory!gatech!darwin.sura.net!ra!mimsy!sdd.comsat.com!ctd.comsat.com!news!neal
- From: neal@ctd.comsat.com (Neal Becker)
- Newsgroups: comp.sys.hp
- Subject: Painless remote X execution
- Message-ID: <NEAL.93Jan28133827@neal.ctd.comsat.com>
- Date: 28 Jan 93 18:38:27 GMT
- Organization: COMSAT Labs
- Lines: 132
- NNTP-Posting-Host: neal.ctd.comsat.com
- X-Md4-Signature: bcbfa3b8472346b3f0fcbf0598036fa3
-
- This includes 3 files. rxterm opens a remote xterm, while rx host cmd
- executes any arbitrary command.
-
- Since there is no way to get rid of the parent remsh on hpux, I have
- written a devilish bit of code to go along with this - daemon.c will
- run any program as a daemon.
-
- Enjoy!
-
- -------------------------------------------------------------
- # This is a shell archive. Remove anything before this line,
- # then unpack it by saving it in a file and typing "sh file".
- #
- # Wrapped by Neal Becker <neal@neal> on Thu Jan 28 13:34:15 1993
- #
- # This archive contains:
- # rx
- #
-
- LANG=""; export LANG
- PATH=/bin:/usr/bin:$PATH; export PATH
-
- a - rx
- echo mkdir - rx
- mkdir rx
-
- a - rx/rx
- echo x - rx/rx
- cat >rx/rx <<'@EOF'
- #!/bin/sh
- host=$1
- shift;
- /usr/bin/X11/xhost +$host > /dev/null
-
- case $SHELL in
- *csh)
-
- case $DISPLAY in
- shmlink:* | :*) remsh $host -n "setenv DISPLAY `hostname`:0;setenv XENVIRONMENT $XENVIRONMENT;/usr/local/bin/daemon $*" ;;
- *) remsh $host -n "setenv DISPLAY $DISPLAY;setenv XENVIRONMENT $XENVIRONMENT;/usr/local/bin/daemon $*" ;;
- esac
-
- ;;
-
- *)
- case $DISPLAY in
- shmlink:* | :*) remsh $host -n "DISPLAY=`hostname`:0 XENVIRONMENT=$XENVIRONMENT /usr/local/bin/daemon $*" ;;
- *) remsh $host -n "DISPLAY=$DISPLAY XENVIRONMENT=$XENVIRONMENT /usr/local/bin/daemon $*" ;;
- esac
-
- ;;
- esac
- @EOF
-
- chmod 755 rx/rx
-
- a - rx/rxterm
- echo x - rx/rxterm
- cat >rx/rxterm <<'@EOF'
- #!/bin/sh
- host=$1
- shift;
- /usr/bin/X11/xhost +$host > /dev/null
- case $SHELL in
- *csh)
-
- case $DISPLAY in
- shmlink:* | :*) remsh $host -n "setenv DISPLAY `hostname`:0;setenv XENVIRONMENT $XENVIRONMENT;/usr/local/bin/daemon xterm -n xterm@$host $*" ;;
- *) remsh $host -n "setenv DISPLAY $DISPLAY;setenv XENVIRONMENT $XENVIRONMENT;/usr/local/bin/daemon xterm -n xterm@$host $*" ;;
- esac
-
- ;;
- *)
- case $DISPLAY in
- shmlink:* | :*) remsh $host -n "DISPLAY=`hostname`:0 XENVIRONMENT=$XENVIRONMENT /usr/local/bin/daemon xterm -n xterm@$host $*" ;;
- *) remsh $host -n "DISPLAY=$DISPLAY XENVIRONMENT=$XENVIRONMENT /usr/local/bin/daemon xterm -n xterm@$host $*" ;;
- esac
-
- ;;
-
- esac
- @EOF
-
- chmod 755 rx/rxterm
-
- a - rx/daemon.c
- echo x - rx/daemon.c
- cat >rx/daemon.c <<'@EOF'
- #include <unistd.h> /* For _SC_OPEN_MAX */
- #include <stdio.h>
- #include <sys/file.h>
- #include <stdlib.h>
-
- static void Usage( const char* prog ) {
- fprintf( stderr, "usage: %s <prog>\n", prog );
- exit( 1 );
- }
-
- main( int argc, char* argv[] ) {
- long tblsiz = sysconf(_SC_OPEN_MAX);
- int c;
- char * NewArgv[ 256 ];
-
- if( argc < 2 ) Usage( argv[ 0 ] );
-
- switch( fork() ) {
- case -1:
- perror( argv[ 0 ] );
- exit( 1 );
-
- case 0:
- setsid();
- for (c = 0; c < tblsiz; c++)
- (void) close(c);
- (void) open("/", O_RDONLY);
- (void) dup2(0, 1);
- (void) dup2(0, 2);
- execvp( argv[ 1 ], &argv[ 1 ] );
- _exit( -1 );
-
- default:
- exit( 0 );
-
- }
- }
- @EOF
-
- chmod 644 rx/daemon.c
-
- chmod 755 rx
-
- exit 0
-