[29616] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 860 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 17 21:14:16 2007

Date: Mon, 17 Sep 2007 18:14:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 17 Sep 2007     Volume: 11 Number: 860

Today's topics:
    Re: Question on input password on ssh prompt <glex_no-spam@qwest-spam-no.invalid>
    Re: Question on input password on ssh prompt <jgibson@mail.arc.nasa.gov>
    Re: Question on input password on ssh prompt <ben@morrow.me.uk>
    Re: Question on input password on ssh prompt <mluvw47@gmail.com>
    Re: Question on input password on ssh prompt <mluvw47@gmail.com>
    Re: Question on input password on ssh prompt <mluvw47@gmail.com>
    Re: Question on input password on ssh prompt <ben@morrow.me.uk>
    Re: Running Perl script in the backend from Html <x3v0-usenet@yahoo.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Mon, 17 Sep 2007 10:31:22 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Question on input password on ssh prompt
Message-Id: <46ee9dca$0$10306$815e3792@news.qwest.net>

Mav wrote:

> In fact, The actual script I am working actually first generates the
> public key on the PC side(for that PC), then append the public key
> into linux (.ssh/authorized_key) entry thru ssh command. So next time,
> if the PC invokes a command from the PC to linux side thru ssh, it
> will not prompt the password. Any suggestion?

You have to authenticate to have SSH work.  That authentication
can be public key or by providing the password.  You might want
to look at the Expect module, to automate the initial authentication
with the password. Probably the best route is if the ssh keys don't
exist, then to have the script prompt for the password when it
runs, and have it pass it to SSH, using Expect.


------------------------------

Date: Mon, 17 Sep 2007 10:20:35 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Question on input password on ssh prompt
Message-Id: <170920071020352615%jgibson@mail.arc.nasa.gov>

In article <1189894854.343252.54160@22g2000hsm.googlegroups.com>, Mav
<mluvw47@gmail.com> wrote:

> Hi, all
>    I am writing a perl script running on the XP, the machine already
> have openssh installed. The script would call ssh command and send a
> command to the remote host.
> The code like.
> 
>    #my.pl
>    $user = "user";
>    $passwd = "mypasswd";
>    $ipaddress = "somehost";
>    $command = "ls -la";
>     ..
>     print ("Invoke command on host : $ipaddress);
>     system("ssh $user\@$ipaddress $command");
>     #check for error message come back from the system call.
>     #Todo: need to input the password.
>     ...
>   ---end here ---
> 
> However right after I made the system call for ssh, it prompts for the
> password.
> 
>   c:\>perl my.pl
>   Invoke command on host : somehost
>   enter password:   <---  my program stopped right here waiting.
> 
>   I understood that perl provides pm packages (in this case SSH) to
> get this work done, but the script I am going to run, only will get
> the perl installed and perl.dll, not extra module.
> 
>   My question is:
>   1) Is that a way I can feed it the password without install any
> module?, if so, how?
>   2) Or where I can find out more regarding input after prompt
> waiting?
>   3) is that a way I can get the command (in this case ls -la) return
> result?

My answers are:

1. You can configure ssh so that it does not need a password, but uses
public key authorization. This involves generating a public/private key
pair using ssh-keygen (under Unix, anyway), storing the public key on
the remote host, and telling ssh to use your private key on the local
host (ssh-agent and ssh-add). Consult the documentation for your ssh
installation (I am not familiar with openssh).

2. You can pipe a data stream to an external command by using open. See
'perldoc open' or consult the documentation for your Perl installation.
You can also investigate using the Expect.pm module.

3. You can capture the output of any external command by running it
with backticks (``) or the qx() operator rather than the system
function. See 'perldoc perlop' and search for 'qx'.

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


------------------------------

Date: Mon, 17 Sep 2007 18:23:11 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Question on input password on ssh prompt
Message-Id: <vop2s4-lb3.ln1@osiris.mauzo.dyndns.org>


Quoth "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>:
> Mav wrote:
> 
> > In fact, The actual script I am working actually first generates the
> > public key on the PC side(for that PC), then append the public key
> > into linux (.ssh/authorized_key) entry thru ssh command. So next time,
> > if the PC invokes a command from the PC to linux side thru ssh, it
> > will not prompt the password. Any suggestion?
> 
> You have to authenticate to have SSH work.  That authentication
> can be public key or by providing the password.  You might want
> to look at the Expect module, to automate the initial authentication
> with the password. Probably the best route is if the ssh keys don't
> exist, then to have the script prompt for the password when it
> runs, and have it pass it to SSH, using Expect.

No, that won't work, as Expect requires ptys, which WinXP doesn't have.
I think the OP's best way forward is to try Net::SSH::W32Perl, which can
log in with a password.

Ben



------------------------------

Date: Mon, 17 Sep 2007 22:11:48 -0000
From:  Mav <mluvw47@gmail.com>
Subject: Re: Question on input password on ssh prompt
Message-Id: <1190067108.567691.14030@w3g2000hsg.googlegroups.com>

On Sep 17, 10:23 am, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>:
>
> > Mav wrote:
>
> > > In fact, The actual script I am working actually first generates the
> > > public key on the PC side(for that PC), then append the public key
> > > into linux (.ssh/authorized_key) entry thru ssh command. So next time,
> > > if the PC invokes a command from the PC to linux side thru ssh, it
> > > will not prompt the password. Any suggestion?
>
> > You have to authenticate to have SSH work.  That authentication
> > can be public key or by providing the password.  You might want
> > to look at the Expect module, to automate the initial authentication
> > with the password. Probably the best route is if the ssh keys don't
> > exist, then to have the script prompt for the password when it
> > runs, and have it pass it to SSH, using Expect.
>
> No, that won't work, as Expect requires ptys, which WinXP doesn't have.
> I think the OP's best way forward is to try Net::SSH::W32Perl, which can
> log in with a password.
>
> Ben

Thanks, Ben
I looks into the Net::SSH::W32Perl, when I tried to use that I got the
error:

use Net::SSH::W32Perl;
my $ssh = new Net::SSH::W32Perl($host, protocol => 2, debug=>1);

The getpwuid function is unimplemented at C:/Perl/site/lib/Net/SSH/
Perl.pm line
110.

line 110 on Perl.pm regarding to environment variable $HOME on PC. Do
you encounter the same problem? That means that I have to set the
$HOME in my script?

Thanks,
Mav





------------------------------

Date: Mon, 17 Sep 2007 22:52:24 -0000
From:  Mav <mluvw47@gmail.com>
Subject: Re: Question on input password on ssh prompt
Message-Id: <1190069544.785906.134410@57g2000hsv.googlegroups.com>

On Sep 17, 10:23 am, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>:
>
> > Mav wrote:
>
> > > In fact, The actual script I am working actually first generates the
> > > public key on the PC side(for that PC), then append the public key
> > > into linux (.ssh/authorized_key) entry thru ssh command. So next time,
> > > if the PC invokes a command from the PC to linux side thru ssh, it
> > > will not prompt the password. Any suggestion?
>
> > You have to authenticate to have SSH work.  That authentication
> > can be public key or by providing the password.  You might want
> > to look at the Expect module, to automate the initial authentication
> > with the password. Probably the best route is if the ssh keys don't
> > exist, then to have the script prompt for the password when it
> > runs, and have it pass it to SSH, using Expect.
>
> No, that won't work, as Expect requires ptys, which WinXP doesn't have.
> I think the OP's best way forward is to try Net::SSH::W32Perl, which can
> log in with a password.
>
> Ben

my code:
use Net::SSH::W32Perl;
my $ssh = new Net::SSH::W32Perl($host, protocol => 2, debug=>1);
$ssh->login('user', 'passwd');
my ($out, $err, $exit) = $ssh->cmd('ls');

However, if I set the $HOME =c:\LLL_work, my script works, however, it
hangs almost 1 hr, nothing returns. (See below)

My question:
1) Is that a bug on the module that need to set $HOME or something I
did wrong?
2) I could not figure out why it hangs? seems my ssh (I ran from
cmd.exe), I have no problem to access the Remote Debian box from the
XP. Only problem is from my script?

I have the perl on PC.
This is perl, v5.8.8 built for MSWin32-x86-multi-thread
(with 50 registered patches, see perl -V for more detail)
Binary build 820 [274739] provided by ActiveState http://www.ActiveState.com
Built Jan 23 2007 15:57:46

== Here is what I did ===
C:\>set HOME=c:\LLL_work

C:\LLL_work>perl x.pl
D510: Reading configuration data c:\LLL_work/.ssh/config
D510: Reading configuration data /etc/ssh_config
D510: Connecting to osm-juno2.caclab.cac.cpqcorp.net, port 22.
D510: Socket created, turning on blocking...
D510: Remote version string: SSH-2.0-OpenSSH_4.3p2 Debian-9

D510: Remote protocol version 2.0, remote software version
OpenSSH_4.3p2
 Debian-9
D510: Net::SSH::Perl Version 1.30, protocol version 2.0.
D510: No compat match: OpenSSH_4.3p2 Debian-9.
D510: Connection established.
D510: Sent key-exchange init (KEXINIT), wait response.
D510: Algorithms, c->s: 3des-cbc hmac-sha1 none
D510: Algorithms, s->c: 3des-cbc hmac-sha1 none
D510: Entering Diffie-Hellman Group 1 key exchange.
D510: Sent DH public key, waiting for reply.
D510: Received host key, type 'ssh-dss'.
D510: Permanently added 'Myhost.machine.com' to the list o
f known hosts.
D510: Computing shared secret key.
D510: Verifying server signature.
D510: Waiting for NEWKEYS message.
D510: Enabling incoming encryption/MAC/compression.
D510: Send NEWKEYS, enable outgoing encryption/MAC/compression.
D510: Sending request for user-authentication service.
D510: Service accepted: ssh-userauth.
D510: Trying empty user-authentication request.
D510: Authentication methods that can continue: publickey,password.
D510: Next method to try is publickey.
D510: Next method to try is password.
D510: Trying password authentication.
D510: Login completed, opening dummy shell channel.
D510: channel 0: new [client-session]
D510: Requesting channel_open for channel 0.
D510: channel 0: open confirm rwindow 0 rmax 32768
D510: Got channel open confirmation, requesting shell.
D510: Requesting service shell on channel 0.
D510: channel 1: new [client-session]
D510: Requesting channel_open for channel 1.
D510: Entering interactive session.
D510: Sending command: ls
D510: Requesting service exec on channel 1.
D510: channel 1: open confirm rwindow 0 rmax 32768
D510: input_channel_request: rtype exit-status reply 0
D510: channel 1: rcvd eof
D510: channel 1: output open -> drain
D510: channel 1: rcvd close
D510: channel 1: input open -> closed
D510: channel 1: close_read      <==================Hang right here.



------------------------------

Date: Mon, 17 Sep 2007 23:05:02 -0000
From:  Mav <mluvw47@gmail.com>
Subject: Re: Question on input password on ssh prompt
Message-Id: <1190070302.110198.307670@22g2000hsm.googlegroups.com>

On Sep 17, 10:23 am, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>:
>
> > Mav wrote:
>
> > > In fact, The actual script I am working actually first generates the
> > > public key on the PC side(for that PC), then append the public key
> > > into linux (.ssh/authorized_key) entry thru ssh command. So next time,
> > > if the PC invokes a command from the PC to linux side thru ssh, it
> > > will not prompt the password. Any suggestion?
>
> > You have to authenticate to have SSH work.  That authentication
> > can be public key or by providing the password.  You might want
> > to look at the Expect module, to automate the initial authentication
> > with the password. Probably the best route is if the ssh keys don't
> > exist, then to have the script prompt for the password when it
> > runs, and have it pass it to SSH, using Expect.
>
> No, that won't work, as Expect requires ptys, which WinXP doesn't have.
> I think the OP's best way forward is to try Net::SSH::W32Perl, which can
> log in with a password.
>
> Ben

y code:
use Net::SSH::W32Perl;
my $ssh = new Net::SSH::W32Perl($host, protocol => 2, debug=>1);
$ssh->login('user', 'passwd');
my ($out, $err, $exit) = $ssh->cmd('ls');

However, if I set the $HOME =c:\LLL_work, my script works, however, it
hangs almost 1 hr, nothing returns. (See below)

My question:
1) Is that a bug on the module that need to set $HOME or something I
did wrong?
2) I could not figure out why it hangs? seems my ssh (I ran from
cmd.exe), I have no problem to access the Remote Debian box from the
XP. Only problem is from my script?

I have the perl on PC.
This is perl, v5.8.8 built for MSWin32-x86-multi-thread
(with 50 registered patches, see perl -V for more detail)
Binary build 820 [274739] provided by ActiveState http://www.ActiveState.com
Built Jan 23 2007 15:57:46

== Here is what I did ===
C:\>set HOME=c:\LLL_work

C:\LLL_work>perl x.pl
D510: Reading configuration data c:\LLL_work/.ssh/config
D510: Reading configuration data /etc/ssh_config
D510: Connecting to Myhost.machine.com, port 22.
D510: Socket created, turning on blocking...
D510: Remote version string: SSH-2.0-OpenSSH_4.3p2 Debian-9

D510: Remote protocol version 2.0, remote software version
OpenSSH_4.3p2
 Debian-9
D510: Net::SSH::Perl Version 1.30, protocol version 2.0.
D510: No compat match: OpenSSH_4.3p2 Debian-9.
D510: Connection established.
D510: Sent key-exchange init (KEXINIT), wait response.
D510: Algorithms, c->s: 3des-cbc hmac-sha1 none
D510: Algorithms, s->c: 3des-cbc hmac-sha1 none
D510: Entering Diffie-Hellman Group 1 key exchange.
D510: Sent DH public key, waiting for reply.
D510: Received host key, type 'ssh-dss'.
D510: Permanently added 'Myhost.machine.com' to the list o
f known hosts.
D510: Computing shared secret key.
D510: Verifying server signature.
D510: Waiting for NEWKEYS message.
D510: Enabling incoming encryption/MAC/compression.
D510: Send NEWKEYS, enable outgoing encryption/MAC/compression.
D510: Sending request for user-authentication service.
D510: Service accepted: ssh-userauth.
D510: Trying empty user-authentication request.
D510: Authentication methods that can continue: publickey,password.
D510: Next method to try is publickey.
D510: Next method to try is password.
D510: Trying password authentication.
D510: Login completed, opening dummy shell channel.
D510: channel 0: new [client-session]
D510: Requesting channel_open for channel 0.
D510: channel 0: open confirm rwindow 0 rmax 32768
D510: Got channel open confirmation, requesting shell.
D510: Requesting service shell on channel 0.
D510: channel 1: new [client-session]
D510: Requesting channel_open for channel 1.
D510: Entering interactive session.
D510: Sending command: ls
D510: Requesting service exec on channel 1.
D510: channel 1: open confirm rwindow 0 rmax 32768
D510: input_channel_request: rtype exit-status reply 0
D510: channel 1: rcvd eof
D510: channel 1: output open -> drain
D510: channel 1: rcvd close
D510: channel 1: input open -> closed
D510: channel 1: close_read      <==================Hang right here.



------------------------------

Date: Tue, 18 Sep 2007 01:02:35 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Question on input password on ssh prompt
Message-Id: <r5h3s4-681.ln1@osiris.mauzo.dyndns.org>


Quoth Mav <mluvw47@gmail.com>:
> On Sep 17, 10:23 am, Ben Morrow <b...@morrow.me.uk> wrote:
> > Quoth "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>:
> >
> > > Mav wrote:
> >
> > > > In fact, The actual script I am working actually first generates the
> > > > public key on the PC side(for that PC), then append the public key
> > > > into linux (.ssh/authorized_key) entry thru ssh command. So next time,
> > > > if the PC invokes a command from the PC to linux side thru ssh, it
> > > > will not prompt the password. Any suggestion?
> >
> > > You have to authenticate to have SSH work.  That authentication
> > > can be public key or by providing the password.  You might want
> > > to look at the Expect module, to automate the initial authentication
> > > with the password. Probably the best route is if the ssh keys don't
> > > exist, then to have the script prompt for the password when it
> > > runs, and have it pass it to SSH, using Expect.
> >
> > No, that won't work, as Expect requires ptys, which WinXP doesn't have.
> > I think the OP's best way forward is to try Net::SSH::W32Perl, which can
> > log in with a password.
> 
> I looks into the Net::SSH::W32Perl, when I tried to use that I got the
> error:
> 
> use Net::SSH::W32Perl;
> my $ssh = new Net::SSH::W32Perl($host, protocol => 2, debug=>1);
> 
> The getpwuid function is unimplemented at C:/Perl/site/lib/Net/SSH/
> Perl.pm line
> 110.
> 
> line 110 on Perl.pm regarding to environment variable $HOME on PC. Do
> you encounter the same problem? That means that I have to set the
> $HOME in my script?

Err... yes, looks like it. I always have %HOME% set to my profile
directory anyway under Win32... I guess this could be reported as a bug
in N:S:W32Perl or N:S:Perl: the correct answer would be to use
File::HomeDir. You should probably put

    use File::HomeDir;
    BEGIN { $ENV{HOME} ||= File::HomeDir->my_data }

at the top, which will cause N:S:Perl to look for its config file in
Local Settings\Application Data\.ssh\config . Alternatively, if you
already have an OpenSSH config file elsewhere, simply direct N:S:W32Perl
at it: you will still need to set $ENV{HOME}, even though it will be
ignored.

Ben



------------------------------

Date: Mon, 17 Sep 2007 16:23:20 -0400
From: Ken <x3v0-usenet@yahoo.com>
Subject: Re: Running Perl script in the backend from Html
Message-Id: <2f38$46eee331$d8c34f66$16565@FUSE.NET>

Gunnar Hjalmarsson wrote:
> satish2112@gmail.com wrote:
>> following is my Html code:
>>
>> <form name="form100" method="post" action="script.pl">
>> <textarea cols = "160" rows="12" name="TextArea1" > </textarea>
>> <input align = "left" name="UpdateButton" type= "submit"
>> value="Update" >
>>
>> in the above code, if i click on submit button, a webpage is opened
>> and the script in script.pl is executed.
>>
>> is there any way such that another web-page is not opened and the
>> script is run in the backend?
>>
>> Please help me!!
> 
> I tried...
> 
> http://groups.google.com/group/comp.lang.perl.misc/msg/7ef1507bf9b74338
> 
> Why do you ignore the reply you got so far??
> 
You could also use ajax to do the submit.


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 860
**************************************


home help back first fref pref prev next nref lref last post