| Josef Moellers 2007-10-26, 4:23 am |
| cyrusgreats@gmail.com wrote:
> Hi ,
> I'm trying to interactively sending the username/password to login and
> then send CLI commands usinf ssh, this is the only way I can access
> the device, and then sending the commands when logged in, I used the
> following but it seems does not pass the password, I'm sure one of you
> guyus out there have an idea. Thanks in advance..
>=20
>=20
> #!/usr/bin/perl
>=20
> use IPC::Session;
>=20
> # open ssh session to your applinace
> # -- set timeout of 30 seconds for all send() calls
> my $mybox =3D "10.0.42.111";
> my $session =3D new IPC::Session("ssh -l usrname $mybox",30);
>=20
> # use like 'expect':
> print $session->send("passwd");
>=20
>=20
> Here I see the Password prompt but I can't pass password ..
> cheers
>=20
I don't see anything about ttys in IPC::Session's pod. Therefore I=20
assume that it just spawns off an ssh with a pipe opened between the=20
script and the ssh (I don't have it installed, so I can't check, but you =
can check using some system call trace command, e.g. strace. Beware that =
you must tell strace to follow subprocesses!). For some (security?)=20
reasons, on Linux ssh will open /dev/tty to obtain the password, so you=20
can't send it through the pipe.
It would be better, indeed, to use the Expect module to handle this. On=20
Linux, Expect will communicate with the subprocess through a pseudo tty, =
which is set up as the subprocess' controlling tty and, as such, will be =
accessable through /dev/tty.
Josef
--=20
These are my personal views and not those of Fujitsu Siemens Computers!
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html
|