This perl code that opens a pipe to an rsh subprocess that I wrote has
been working for over a year. It clears a cisco tty, which requires a
confirm. I think this is exactly the situation that is described. I
simply sleep, and then send "\n".
You'll need to replace the hash elements $cs->{'host'} and
$cs->{'command'} with the host and the rsh command to run, respectively.
You may also need to tune the sleep value.
$SLEEP = 2;
sub clearCiscoTty {
my $cs = shift || return '';
my $command = qq{/usr/bin/rsh $cs->{'host'} "$cs->{'command'}"};
$lockFile->log("command: $command");
# Open a pipe to the command to read STDOUT and STDERR:
unless ( open( REXEC, "| $command 1> /dev/null" ) ) {
$lockFile->log("Open to run command failed !");
return -1;
}
sleep $SLEEP;
print REXEC "\n";
sleep $SLEEP;
close(REXEC);
}
On Sat, 16 Mar 2002, Niels Bakker wrote:
> >> On Sat, Mar 16, 2002 at 01:05:56AM -0600, Brian wrote:
> >>> Is there a way I can "answer" this and let the router know "yes"?
> >>> I know that with SNMP or telnet scripting this is easier, but surely
> >>> there exists a way via RSH to just send the router a postive or
> >>> negative response to a y/n question.
>
> > On Sat, 16 Mar 2002, Gert Doering wrote:
> >> Try "echo yes | rsh ..."
>
> * signal@shreve.net (Brian) [Sat 16 Mar 2002, 18:30 CET]:
> > That doesn't appear to work. I even tried using like "echo -e yes \r\n"
> > (and other combinations thereof). It hangs at the confirm prompt, I have
> > to suspend the process then kill it off.
>
> rsh reads from its tty, not from stdin. You can work around this by
> using a program called `pty'; it opens a pseudo tty and runs the program
> given on its command line on it. The source comes with Stevens' book
> _Advanced Programming in the Unix Environment_. Unfortunately I don't
> have my modified rsh anymore that worked on Solaris, as the stock rsh on
> at least 2.6 had some quirks that prevented it from functioning.
>
> Disclaimer: the above is all from memory, and it's been a while since
> I last had to do this. The major problem I had to solve was rsh not
> wanting to run without a pty (i.e., from cron).
>
> Good luck,
>
>
> -- Niels.
>
--C. Jon Larsen Chief Technology Officer, Richweb.com (804.307.6939) SMTP: jlarsen@richweb.com (http://richweb.com/cjl_pgp_pub_key.txt)
Richweb.com: Designing Open Source Internet Business Solutions since 1995 Building Safe, Secure, Reliable Cisco-Powered Networks since 1995
This archive was generated by hypermail 2b29 : Sun Aug 04 2002 - 04:13:38 EDT