Remote shell question
Byron Rakitzis
byron at archone.tamu.edu
Sat Feb 2 03:44:08 AEST 1991
In article <1991Feb1.145242.16915 at bradley.bradley.edu> brad at bradley.bradley.edu (Bradley E. Smith) writes:
>In <1991Feb1.125425.14866 at cbnews.att.com> smk at cbnews.cb.att.com (Stephen M. Kennedy) writes:
>
>>I want to start up a process in the background on a remote machine using
>>remsh (sysV) or rsh (bsd), e.g.,
>
>I had this same problem...what I did was to use a 'C' program below.
>
>#include <stdio.h>
>main()
>{
> int i;
> for (i=0;i<20;i++) {
> close(i);
> }
> i = fork();
> if(i)
> exit(0);
> execl("/usr/openwin/demo/xterm","bradley", "-ls", "-sb", "-fn","9x15", 0);
>}
You don't really need to write a C program to close file-descriptors; any reasonable
shell like sh or rc can do this for you. I have two shell scripts, "rx" and "xr".
I type:
rx goofy
and rx does an rsh to goofy, invoking "xr" with all the necessary arguments. "xr"
then takes care to close the stupid file-descriptors (I've found that going up to 9 is
sufficient), puts xterm in the background and exits. Here are "rx" and "xr" in their
entirety:
-------------
#!/usr/arch/bin/rc
if (! ~ $#* 1) {
echo usage: rx hostname >[1=2]
exit 1
}
# an rx from a local window will have DISPLAY set to unix:0.0; this must be changed.
switch ($DISPLAY) {
case unix:*
~ $#hostname 0 && hostname=`hostname
display=`{echo $DISPLAY | sed s/unix:/$hostname:/}
case *
display=$DISPLAY
}
rsh $1 -n bin/sh/xr $display $1 >/dev/null &
-------------
#!/usr/arch/bin/rc -l
DISPLAY=$1
xterm -ls -n $2 -title $2 </dev/null >/dev/null >[2] /dev/null <[3=] <[4=] <[5=] <[6=] <[7=] <[8=] <[9=] &
# the redirections are a hack to make sure that the rshd knows it can exit
-------------
By the way, this "rx", "xr" setup is due to Paul Haahr, who originally wrote
these scripts in sh.
Byron.
--
Byron Rakitzis
byron at archone.tamu.edu
More information about the Comp.unix.shell
mailing list