me@anywhere.EBay.Sun.COM (Wayne Thompson - IR Workstation Support SE) (03/11/91)
Has anyone come up with a reliable way to use rsh (remote shell) from perl? Rsh can hang causing perl to wait for completion. What I've done to work around the problem is to attach a handler to $SIG{'ALRM'} which kills any rsh commands attached to the current terminal: $SIG{'ALRM'} = 'RemoteConnectionHandler'; foreach $client (sort (keys (%cantalkto))) { $cmd = "rsh $client cat $PASSWD"; ($pid = open (REMOTE_CONNECTION, "$cmd 2>&1 |")) || die "\n$MYNAME: $cmd: $!\n"; alarm ($timeout); while (<REMOTE_CONNECTION>) { alarm (0); ... alarm ($timeout); } alarm (0); close (REMOTE_CONNECTION); } sub RemoteConnectionHandler { &grepkill (&SIGKILL, $cmd); close (REMOTE_CONNECTION); } sub grepkill { local ($sig, $pat, $pid) = @_; $pat =~ s/(\W)/\\$1/g; open (PS, "ps $$|"), <PS>; open (PS, "ps -t".(split (' ', <PS>))[1]."|"), <PS>; kill ($sig, grep (/$pat/, <PS>)); close (PS); } I'm looking for a better way to do this. As this depends on /.rhosts for access, using chat and the ftp port is not a viable alternative. I also notice that rcmd is not availble as a syscall. Any ideas? Wayne