ssh-sftp-perl-users Mailing List for Net::SSH and Net::SFTP - Perl modules (Page 7)
Brought to you by:
dbrobins
You can subscribe to this list here.
2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
(6) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
(4) |
Feb
(15) |
Mar
(13) |
Apr
(8) |
May
(5) |
Jun
(21) |
Jul
(4) |
Aug
(9) |
Sep
(11) |
Oct
(14) |
Nov
(15) |
Dec
(24) |
2005 |
Jan
(10) |
Feb
(20) |
Mar
(16) |
Apr
(10) |
May
(12) |
Jun
(16) |
Jul
(18) |
Aug
(21) |
Sep
(11) |
Oct
(19) |
Nov
(16) |
Dec
(9) |
2006 |
Jan
(17) |
Feb
(32) |
Mar
(60) |
Apr
(21) |
May
(24) |
Jun
(1) |
Jul
(6) |
Aug
(18) |
Sep
(4) |
Oct
(9) |
Nov
(31) |
Dec
(10) |
2007 |
Jan
(8) |
Feb
(11) |
Mar
(3) |
Apr
(7) |
May
(4) |
Jun
(6) |
Jul
(7) |
Aug
(3) |
Sep
(2) |
Oct
(5) |
Nov
(5) |
Dec
(5) |
2008 |
Jan
(12) |
Feb
(5) |
Mar
(7) |
Apr
(4) |
May
(37) |
Jun
(9) |
Jul
(24) |
Aug
(5) |
Sep
(2) |
Oct
(7) |
Nov
(6) |
Dec
(7) |
2009 |
Jan
(18) |
Feb
(9) |
Mar
(14) |
Apr
(14) |
May
(1) |
Jun
(14) |
Jul
(4) |
Aug
(6) |
Sep
(4) |
Oct
(12) |
Nov
(4) |
Dec
|
2010 |
Jan
|
Feb
(3) |
Mar
|
Apr
(1) |
May
(4) |
Jun
|
Jul
(6) |
Aug
(6) |
Sep
|
Oct
(7) |
Nov
(2) |
Dec
(5) |
2011 |
Jan
(2) |
Feb
|
Mar
|
Apr
(1) |
May
(8) |
Jun
(1) |
Jul
|
Aug
(2) |
Sep
|
Oct
(4) |
Nov
(9) |
Dec
(7) |
2012 |
Jan
(1) |
Feb
(19) |
Mar
(4) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
|
Feb
|
Mar
(2) |
Apr
(2) |
May
|
Jun
(5) |
Jul
(3) |
Aug
(1) |
Sep
|
Oct
|
Nov
(6) |
Dec
|
2014 |
Jan
(7) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
2015 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
2016 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
2018 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Ian D. <Ian...@bd...> - 2009-06-17 14:05:51
|
Amardeep I responded earlier that creating password-less public/private keys was an option, but the code I gave to login using a password is what was asked for (and frankly easier to set up for the uninitiated than using SSH-keygen). I agree that passwordless SSH login is a much better solution if only because it does not require passwords to be 'hard-coded' into scripts or config files. By the way SreeHari I would seriously recommend *not* using the root account to try out this script. You should set up a separate user account with limited access if you are going to be doing this. Regards Ian ________________________________ From: <<<<Amar>>>> [mailto:ama...@gm...] Sent: 17 June 2009 13:17 To: cheerla sreehari Cc: Ian Docherty; ssh...@li... Subject: Re: [Ssh-sftp-perl-users] Problem With Net::SSH:Perl Hello You need to create public/private keys via SSH-keygen You can refer for any documentation of how to set up password less SSH login. ~Amardeep. On Wed, Jun 17, 2009 at 3:36 PM, cheerla sreehari <ch....@gm...> wrote: Hi , I exactly used the code given by you by just changing the $host and $passwd . When I execute that it is still prompting for the password . So we need to configure SSH for not prompting the password ? Thanks for the help . Regards, SreeHari CH On Wed, Jun 17, 2009 at 5:32 AM, Ian Docherty <Ian...@bd...> wrote: Hi You need to include all of your code when you report problems, or at least a 'cut-down' fully working program that demonstrates the problem. If you had done so in this case we could have seen that you had not included the following in your perl program. use strict; use warnings; I can tell that you have not done so since you your interactive=>FALSE would have given a warning like Bareword "FALSE" not allowed while "strict subs" in use at ssh.pl line 10. This is doing the exact opposite of what you are expecting. Since you have not turned on strict and warnings pragmas then perl is converting the FALSE into a scalar, which is then being evaluated as a true value so requesting the prompt! If you read the documentation you will see that it defaults to false (perl false not FALSE) so it should not request the password. A complete example (which I have tested) is as follows. #!/usr/bin/perl use Net::SSH::Perl; use strict; use warnings; my $host = 'your.domain.com'; my $user = 'root'; my $passwd = 'secret'; my $scon = Net::SSH::Perl->new ($host); $scon->login($user, $passwd); print "looking around...\n"; my ($output, $errors, $exit) = $scon->cmd("ls -l"); print "output=[$output] errors=[$errors] exit=[$exit]\n"; If this still does not work then you have to double check that you can ssh onto the host using the credentials you are putting into your program. Regards Ian ________________________________ From: cheerla sreehari [mailto:ch....@gm...] Sent: 17 June 2009 06:22 To: ssh...@li... Subject: [Ssh-sftp-perl-users] Problem With Net::SSH:Perl Hi , I am using the following code to connect to the remote host . use Net::SSH::Perl ; $scon = Net::SSH::Perl->new ("$host",interactive=>FALSE); $scon->login("root","$passwd"); print "looking around ...\n"; ($output,$errors,$exit) = $scon->cmd("ls -l"); print $output; When I execute this code , it is prompting for the password . I want to ssh without prompting for the password . Please suggest me how I can modify the above code to ssh a client without prompting for the password . Thanks in Advance . Regards, SreeHari CH This email is confidential and intended solely for the use of the individual to whom it is addressed. Any views or opinions presented are solely those of the author and do not necessarily represent those of RedBee Media Metadata. If you are not the intended recipient, be advised that you have received this email in error and that any use, dissemination, forwarding, printing, or copying of this email is strictly prohibited. If you have received this email in error please notify the sender. Red Bee Media Metadata is a trading name of Broadcasting Dataservices Limited. Registered in England and Wales No.: 2554733. Registered Office: 201 Wood Lane, London W12 7TP, UK. Broadcasting Dataservices Limited is a wholly owned subsidiary of Red Bee Media Limited. ------------------------------------------------------------------------ ------ Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects _______________________________________________ Ssh-sftp-perl-users mailing list Ssh...@li... https://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users This email is confidential and intended solely for the use of the individual to whom it is addressed. Any views or opinions presented are solely those of the author and do not necessarily represent those of RedBee Media Metadata. If you are not the intended recipient, be advised that you have received this email in error and that any use, dissemination, forwarding, printing, or copying of this email is strictly prohibited. If you have received this email in error please notify the sender. Red Bee Media Metadata is a trading name of Broadcasting Dataservices Limited. Registered in England and Wales No.: 2554733. Registered Office: 201 Wood Lane, London W12 7TP, UK. Broadcasting Dataservices Limited is a wholly owned subsidiary of Red Bee Media Limited. |
From: <<<<Amar>>>> <ama...@gm...> - 2009-06-17 13:22:33
|
Hello You need to create public/private keys via SSH-keygen You can refer for any documentation of how to set up password less SSH login. ~Amardeep. On Wed, Jun 17, 2009 at 3:36 PM, cheerla sreehari <ch....@gm...>wrote: > Hi , > > I exactly used the code given by you by just changing the $host and $passwd > . When I execute that it is still prompting for the password . > > So we need to configure SSH for not prompting the password ? > > Thanks for the help . > > Regards, > SreeHari CH > > > On Wed, Jun 17, 2009 at 5:32 AM, Ian Docherty <Ian...@bd...> wrote: > >> Hi >> >> You need to include all of your code when you report problems, or at least >> a ‘cut-down’ fully working program that demonstrates the problem. >> >> >> >> If you had done so in this case we could have seen that you had not >> included the following in your perl program. >> >> >> >> *use strict;* >> >> *use warnings;* >> >> * * >> >> I can tell that you have not done so since you your *interactive=>FALSE*would have given a warning like >> >> >> >> *Bareword "FALSE" not allowed while "strict subs" in use at ssh.pl line >> 10.* >> >> >> >> This is doing the exact opposite of what you are expecting. Since you have >> not turned on *strict* and *warnings* pragmas then perl is converting the >> *FALSE* into a scalar, which is then being evaluated as a true value so >> requesting the prompt! >> >> >> >> If you read the documentation you will see that it defaults to false (perl >> false not FALSE) so it should not request the password. >> >> >> >> A complete example (which I have tested) is as follows. >> >> >> >> #!/usr/bin/perl >> >> use Net::SSH::Perl; >> >> >> >> use strict; >> >> use warnings; >> >> >> >> my $host = 'your.domain.com'; >> >> my $user = 'root'; >> >> my $passwd = 'secret'; >> >> >> >> my $scon = Net::SSH::Perl->new ($host); >> >> $scon->login($user, $passwd); >> >> print "looking around...\n"; >> >> my ($output, $errors, $exit) = $scon->cmd("ls -l"); >> >> print "output=[$output] errors=[$errors] exit=[$exit]\n"; >> >> >> >> If this still does not work then you have to double check that you can ssh >> onto the host using the credentials you are putting into your program. >> >> >> >> Regards >> >> Ian >> >> >> ------------------------------ >> >> *From:* cheerla sreehari [mailto:ch....@gm...] >> *Sent:* 17 June 2009 06:22 >> *To:* ssh...@li... >> *Subject:* [Ssh-sftp-perl-users] Problem With Net::SSH:Perl >> >> >> >> Hi , >> >> I am using the following code to connect to the remote host . >> use Net::SSH::Perl ; >> >> $scon = Net::SSH::Perl->new ("$host",interactive=>FALSE); >> $scon->login("root","$passwd"); >> print "looking around ...\n"; >> ($output,$errors,$exit) = $scon->cmd("ls -l"); >> print $output; >> >> >> >> When I execute this code , it is prompting for the password . >> I want to ssh without prompting for the password . >> >> Please suggest me how I can modify the above code to ssh a client without >> prompting for the password . >> >> Thanks in Advance . >> >> Regards, >> SreeHari CH >> This email is confidential and intended solely for the use of the >> individual to whom it is addressed. Any views or opinions presented are >> solely those of the author and do not necessarily represent those of RedBee >> Media Metadata. If you are not the intended recipient, be advised that you >> have received this email in error and that any use, dissemination, >> forwarding, printing, or copying of this email is strictly prohibited. If >> you have received this email in error please notify the sender. >> >> Red Bee Media Metadata is a trading name of Broadcasting Dataservices >> Limited. >> Registered in England and Wales No.: 2554733. Registered Office: 201 Wood >> Lane, London W12 7TP, UK. >> Broadcasting Dataservices Limited is a wholly owned subsidiary of Red Bee >> Media Limited. >> > > > > ------------------------------------------------------------------------------ > Crystal Reports - New Free Runtime and 30 Day Trial > Check out the new simplified licensing option that enables unlimited > royalty-free distribution of the report engine for externally facing > server and web deployment. > http://p.sf.net/sfu/businessobjects > _______________________________________________ > Ssh-sftp-perl-users mailing list > Ssh...@li... > https://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users > > |
From: Ian D. <Ian...@bd...> - 2009-06-17 10:43:54
|
Hi Two things. First double (triple) check that the username, password combination works from the command line. Second add the debug=>1 option to the new and post the debug output you get when you try to make a connection. my $scon = Net::SSH::Perl->new ($host, debug=>1); Regards Ian ________________________________ From: cheerla sreehari [mailto:ch....@gm...] Sent: 17 June 2009 11:06 To: Ian Docherty Cc: ssh...@li... Subject: Re: [Ssh-sftp-perl-users] Problem With Net::SSH:Perl Hi , I exactly used the code given by you by just changing the $host and $passwd . When I execute that it is still prompting for the password . So we need to configure SSH for not prompting the password ? Thanks for the help . Regards, SreeHari CH On Wed, Jun 17, 2009 at 5:32 AM, Ian Docherty <Ian...@bd...> wrote: Hi You need to include all of your code when you report problems, or at least a 'cut-down' fully working program that demonstrates the problem. If you had done so in this case we could have seen that you had not included the following in your perl program. use strict; use warnings; I can tell that you have not done so since you your interactive=>FALSE would have given a warning like Bareword "FALSE" not allowed while "strict subs" in use at ssh.pl line 10. This is doing the exact opposite of what you are expecting. Since you have not turned on strict and warnings pragmas then perl is converting the FALSE into a scalar, which is then being evaluated as a true value so requesting the prompt! If you read the documentation you will see that it defaults to false (perl false not FALSE) so it should not request the password. A complete example (which I have tested) is as follows. #!/usr/bin/perl use Net::SSH::Perl; use strict; use warnings; my $host = 'your.domain.com'; my $user = 'root'; my $passwd = 'secret'; my $scon = Net::SSH::Perl->new ($host); $scon->login($user, $passwd); print "looking around...\n"; my ($output, $errors, $exit) = $scon->cmd("ls -l"); print "output=[$output] errors=[$errors] exit=[$exit]\n"; If this still does not work then you have to double check that you can ssh onto the host using the credentials you are putting into your program. Regards Ian ________________________________ From: cheerla sreehari [mailto:ch....@gm...] Sent: 17 June 2009 06:22 To: ssh...@li... Subject: [Ssh-sftp-perl-users] Problem With Net::SSH:Perl Hi , I am using the following code to connect to the remote host . use Net::SSH::Perl ; $scon = Net::SSH::Perl->new ("$host",interactive=>FALSE); $scon->login("root","$passwd"); print "looking around ...\n"; ($output,$errors,$exit) = $scon->cmd("ls -l"); print $output; When I execute this code , it is prompting for the password . I want to ssh without prompting for the password . Please suggest me how I can modify the above code to ssh a client without prompting for the password . Thanks in Advance . Regards, SreeHari CH This email is confidential and intended solely for the use of the individual to whom it is addressed. Any views or opinions presented are solely those of the author and do not necessarily represent those of RedBee Media Metadata. If you are not the intended recipient, be advised that you have received this email in error and that any use, dissemination, forwarding, printing, or copying of this email is strictly prohibited. If you have received this email in error please notify the sender. Red Bee Media Metadata is a trading name of Broadcasting Dataservices Limited. Registered in England and Wales No.: 2554733. Registered Office: 201 Wood Lane, London W12 7TP, UK. Broadcasting Dataservices Limited is a wholly owned subsidiary of Red Bee Media Limited. This email is confidential and intended solely for the use of the individual to whom it is addressed. Any views or opinions presented are solely those of the author and do not necessarily represent those of RedBee Media Metadata. If you are not the intended recipient, be advised that you have received this email in error and that any use, dissemination, forwarding, printing, or copying of this email is strictly prohibited. If you have received this email in error please notify the sender. Red Bee Media Metadata is a trading name of Broadcasting Dataservices Limited. Registered in England and Wales No.: 2554733. Registered Office: 201 Wood Lane, London W12 7TP, UK. Broadcasting Dataservices Limited is a wholly owned subsidiary of Red Bee Media Limited. |
From: cheerla s. <ch....@gm...> - 2009-06-17 10:06:08
|
Hi , I exactly used the code given by you by just changing the $host and $passwd . When I execute that it is still prompting for the password . So we need to configure SSH for not prompting the password ? Thanks for the help . Regards, SreeHari CH On Wed, Jun 17, 2009 at 5:32 AM, Ian Docherty <Ian...@bd...> wrote: > Hi > > You need to include all of your code when you report problems, or at least > a ‘cut-down’ fully working program that demonstrates the problem. > > > > If you had done so in this case we could have seen that you had not > included the following in your perl program. > > > > *use strict;* > > *use warnings;* > > * * > > I can tell that you have not done so since you your *interactive=>FALSE*would have given a warning like > > > > *Bareword "FALSE" not allowed while "strict subs" in use at ssh.pl line > 10.* > > > > This is doing the exact opposite of what you are expecting. Since you have > not turned on *strict* and *warnings* pragmas then perl is converting the > *FALSE* into a scalar, which is then being evaluated as a true value so > requesting the prompt! > > > > If you read the documentation you will see that it defaults to false (perl > false not FALSE) so it should not request the password. > > > > A complete example (which I have tested) is as follows. > > > > #!/usr/bin/perl > > use Net::SSH::Perl; > > > > use strict; > > use warnings; > > > > my $host = 'your.domain.com'; > > my $user = 'root'; > > my $passwd = 'secret'; > > > > my $scon = Net::SSH::Perl->new ($host); > > $scon->login($user, $passwd); > > print "looking around...\n"; > > my ($output, $errors, $exit) = $scon->cmd("ls -l"); > > print "output=[$output] errors=[$errors] exit=[$exit]\n"; > > > > If this still does not work then you have to double check that you can ssh > onto the host using the credentials you are putting into your program. > > > > Regards > > Ian > > > ------------------------------ > > *From:* cheerla sreehari [mailto:ch....@gm...] > *Sent:* 17 June 2009 06:22 > *To:* ssh...@li... > *Subject:* [Ssh-sftp-perl-users] Problem With Net::SSH:Perl > > > > Hi , > > I am using the following code to connect to the remote host . > use Net::SSH::Perl ; > > $scon = Net::SSH::Perl->new ("$host",interactive=>FALSE); > $scon->login("root","$passwd"); > print "looking around ...\n"; > ($output,$errors,$exit) = $scon->cmd("ls -l"); > print $output; > > > > When I execute this code , it is prompting for the password . > I want to ssh without prompting for the password . > > Please suggest me how I can modify the above code to ssh a client without > prompting for the password . > > Thanks in Advance . > > Regards, > SreeHari CH > This email is confidential and intended solely for the use of the > individual to whom it is addressed. Any views or opinions presented are > solely those of the author and do not necessarily represent those of RedBee > Media Metadata. If you are not the intended recipient, be advised that you > have received this email in error and that any use, dissemination, > forwarding, printing, or copying of this email is strictly prohibited. If > you have received this email in error please notify the sender. > > Red Bee Media Metadata is a trading name of Broadcasting Dataservices > Limited. > Registered in England and Wales No.: 2554733. Registered Office: 201 Wood > Lane, London W12 7TP, UK. > Broadcasting Dataservices Limited is a wholly owned subsidiary of Red Bee > Media Limited. > |
From: Ian D. <Ian...@bd...> - 2009-06-17 09:33:20
|
Hi You need to include all of your code when you report problems, or at least a 'cut-down' fully working program that demonstrates the problem. If you had done so in this case we could have seen that you had not included the following in your perl program. use strict; use warnings; I can tell that you have not done so since you your interactive=>FALSE would have given a warning like Bareword "FALSE" not allowed while "strict subs" in use at ssh.pl line 10. This is doing the exact opposite of what you are expecting. Since you have not turned on strict and warnings pragmas then perl is converting the FALSE into a scalar, which is then being evaluated as a true value so requesting the prompt! If you read the documentation you will see that it defaults to false (perl false not FALSE) so it should not request the password. A complete example (which I have tested) is as follows. #!/usr/bin/perl use Net::SSH::Perl; use strict; use warnings; my $host = 'your.domain.com'; my $user = 'root'; my $passwd = 'secret'; my $scon = Net::SSH::Perl->new ($host); $scon->login($user, $passwd); print "looking around...\n"; my ($output, $errors, $exit) = $scon->cmd("ls -l"); print "output=[$output] errors=[$errors] exit=[$exit]\n"; If this still does not work then you have to double check that you can ssh onto the host using the credentials you are putting into your program. Regards Ian ________________________________ From: cheerla sreehari [mailto:ch....@gm...] Sent: 17 June 2009 06:22 To: ssh...@li... Subject: [Ssh-sftp-perl-users] Problem With Net::SSH:Perl Hi , I am using the following code to connect to the remote host . use Net::SSH::Perl ; $scon = Net::SSH::Perl->new ("$host",interactive=>FALSE); $scon->login("root","$passwd"); print "looking around ...\n"; ($output,$errors,$exit) = $scon->cmd("ls -l"); print $output; When I execute this code , it is prompting for the password . I want to ssh without prompting for the password . Please suggest me how I can modify the above code to ssh a client without prompting for the password . Thanks in Advance . Regards, SreeHari CH This email is confidential and intended solely for the use of the individual to whom it is addressed. Any views or opinions presented are solely those of the author and do not necessarily represent those of RedBee Media Metadata. If you are not the intended recipient, be advised that you have received this email in error and that any use, dissemination, forwarding, printing, or copying of this email is strictly prohibited. If you have received this email in error please notify the sender. Red Bee Media Metadata is a trading name of Broadcasting Dataservices Limited. Registered in England and Wales No.: 2554733. Registered Office: 201 Wood Lane, London W12 7TP, UK. Broadcasting Dataservices Limited is a wholly owned subsidiary of Red Bee Media Limited. |
From: cheerla s. <ch....@gm...> - 2009-06-17 05:21:33
|
Hi , I am using the following code to connect to the remote host . use Net::SSH::Perl ; $scon = Net::SSH::Perl->new ("$host",interactive=>FALSE); $scon->login("root","$passwd"); print "looking around ...\n"; ($output,$errors,$exit) = $scon->cmd("ls -l"); print $output; When I execute this code , it is prompting for the password . I want to ssh without prompting for the password . Please suggest me how I can modify the above code to ssh a client without prompting for the password . Thanks in Advance . Regards, SreeHari CH |
From: Ian D. <Ian...@bd...> - 2009-06-15 16:04:23
|
Hi In general you can post it, it may not be the correct forum and you may get no answer. A simple google would find more appropriate places to post your request, such as http://forums.tutorialized.com/perl-and-cgi-90/ However having said that, it sounds like your problem is that the location (cgi-bin) is not configured to run perl scripts, or does not recognise the .pl extension as a script (try naming it sree.cgi) or some other reason. This may be enough to get you started, if not other forums may be better suited. You need to provide as much information as you can when you ask for help. * What operating system you are running on * What web server are you using (apache, IIS, etc) * What error messages you get, if any. * What you expected to happen (you did this) * What actually happened (you did this) * What you have tried already (you did this) Try what I recommended, if this does not work provide me (off-list not copied to the list) and I will see if there is anything else you can try. Regards Ian ________________________________ From: cheerla sreehari [mailto:ch....@gm...] Sent: 15 June 2009 10:44 To: ssh...@li... Subject: [Ssh-sftp-perl-users] Problems with CGI scripts Hi , I don't know whether I can post this question in this forum . I have a problem with CGI Scripts . I am trying to execute a script using <a href="cgi-bin/sree.pl">Hello</a> When I click "Hello" it is asking to save / open file sree.pl . Even I tried giving 755 permissions to sree.pl Please suggest me the solution . Regards, SreeHari Ch This email is confidential and intended solely for the use of the individual to whom it is addressed. Any views or opinions presented are solely those of the author and do not necessarily represent those of RedBee Media Metadata. If you are not the intended recipient, be advised that you have received this email in error and that any use, dissemination, forwarding, printing, or copying of this email is strictly prohibited. If you have received this email in error please notify the sender. Red Bee Media Metadata is a trading name of Broadcasting Dataservices Limited. Registered in England and Wales No.: 2554733. Registered Office: 201 Wood Lane, London W12 7TP, UK. Broadcasting Dataservices Limited is a wholly owned subsidiary of Red Bee Media Limited. |
From: cheerla s. <ch....@gm...> - 2009-06-15 09:46:38
|
Hi , I don't know whether I can post this question in this forum . I have a problem with CGI Scripts . I am trying to execute a script using <a href="cgi-bin/sree.pl">Hello</a> When I click "Hello" it is asking to save / open file sree.pl . Even I tried giving 755 permissions to sree.pl Please suggest me the solution . Regards, SreeHari Ch |
From: Ian D. <Ian...@bd...> - 2009-06-11 06:52:13
|
You can't specify a password to Net::SSH (it states so in the documentation) You can either set up SSH to not require a password. You have to look up how to do password-less SSH between client and host. This involves creating a public-private keypair on the client and then installing the public key on the host. This then allows you to ssh from the client to the host without giving a password. (Google for 'passwordless ssh') Or you have to provide a password to SSH. Look at Net::SSH::Expect or Net::SSH::Perl which allows you to enter a password. Regards Ian ________________________________ From: cheerla sreehari [mailto:ch....@gm...] Sent: 11 June 2009 05:22 To: Ian Docherty Cc: ssh...@li... Subject: Re: [Ssh-sftp-perl-users] Problem With Net::SSH No .....I am not able to do SSH without entering the password . Is there any way I can automate this password . or is there any way I can give the password for NET::SSH . Please suggest me . Regards, SreeHari Ch On Wed, Jun 10, 2009 at 6:08 PM, Ian Docherty <Ian...@bd...> wrote: Hi Are you able to do an SSH command from the command line to the remote host without entering a password? In other words are your public keys set up on the host correctly? Regards Ian ________________________________ From: cheerla sreehari [mailto:ch....@gm...] Sent: 10 June 2009 07:51 To: ssh...@li... Subject: [Ssh-sftp-perl-users] Problem With Net::SSH Hi All , I am trying to do ssh to a machine from my client using the following CODE : use Net::SSH qw(sshopen2); use strict; my $user = "root"; my $host = "changeme"; my $cmd = "ls /root/"; sshopen2("$user\@$host", *READER, *WRITER, "$cmd") || die "ssh: $!"; while (<READER>) { chomp(); print "$_\n"; } close(READER); close(WRITER); When I execute this code it says "Permission denied (publickey,keyboard-interactive)." .Am I missing something here ? The host I am trying to login is a SUSE machine . Please suggest me the solution to get of this problem . Regards, SreeHari Ch This email is confidential and intended solely for the use of the individual to whom it is addressed. Any views or opinions presented are solely those of the author and do not necessarily represent those of RedBee Media Metadata. If you are not the intended recipient, be advised that you have received this email in error and that any use, dissemination, forwarding, printing, or copying of this email is strictly prohibited. If you have received this email in error please notify the sender. Red Bee Media Metadata is a trading name of Broadcasting Dataservices Limited. Registered in England and Wales No.: 2554733. Registered Office: 201 Wood Lane, London W12 7TP, UK. Broadcasting Dataservices Limited is a wholly owned subsidiary of Red Bee Media Limited. This email is confidential and intended solely for the use of the individual to whom it is addressed. Any views or opinions presented are solely those of the author and do not necessarily represent those of RedBee Media Metadata. If you are not the intended recipient, be advised that you have received this email in error and that any use, dissemination, forwarding, printing, or copying of this email is strictly prohibited. If you have received this email in error please notify the sender. Red Bee Media Metadata is a trading name of Broadcasting Dataservices Limited. Registered in England and Wales No.: 2554733. Registered Office: 201 Wood Lane, London W12 7TP, UK. Broadcasting Dataservices Limited is a wholly owned subsidiary of Red Bee Media Limited. |
From: cheerla s. <ch....@gm...> - 2009-06-11 04:23:23
|
No .....I am not able to do SSH without entering the password . Is there any way I can automate this password . or is there any way I can give the password for NET::SSH . Please suggest me . Regards, SreeHari Ch On Wed, Jun 10, 2009 at 6:08 PM, Ian Docherty <Ian...@bd...> wrote: > Hi > > Are you able to do an SSH command from the command line to the remote host > without entering a password? > > > > In other words are your public keys set up on the host correctly? > > > > Regards > > Ian > > > ------------------------------ > > *From:* cheerla sreehari [mailto:ch....@gm...] > *Sent:* 10 June 2009 07:51 > *To:* ssh...@li... > *Subject:* [Ssh-sftp-perl-users] Problem With Net::SSH > > > > Hi All , > > I am trying to do ssh to a machine from my client using the following CODE > : > > use Net::SSH qw(sshopen2); > use strict; > > my $user = "root"; > my $host = "changeme"; > my $cmd = "ls /root/"; > > sshopen2("$user\@$host", *READER, *WRITER, "$cmd") || die "ssh: $!"; > > while (<READER>) { > chomp(); > print "$_\n"; > } > > close(READER); > close(WRITER); > > When I execute this code it says "*Permission denied > (publickey,keyboard-interactive)*." .Am I missing something here ? > > The host I am trying to login is a SUSE machine . > Please suggest me the solution to get of this problem . > > Regards, > SreeHari Ch > This email is confidential and intended solely for the use of the > individual to whom it is addressed. Any views or opinions presented are > solely those of the author and do not necessarily represent those of RedBee > Media Metadata. If you are not the intended recipient, be advised that you > have received this email in error and that any use, dissemination, > forwarding, printing, or copying of this email is strictly prohibited. If > you have received this email in error please notify the sender. > > Red Bee Media Metadata is a trading name of Broadcasting Dataservices > Limited. > Registered in England and Wales No.: 2554733. Registered Office: 201 Wood > Lane, London W12 7TP, UK. > Broadcasting Dataservices Limited is a wholly owned subsidiary of Red Bee > Media Limited. > |
From: Ian D. <Ian...@bd...> - 2009-06-10 13:13:41
|
Hi Are you able to do an SSH command from the command line to the remote host without entering a password? In other words are your public keys set up on the host correctly? Regards Ian ________________________________ From: cheerla sreehari [mailto:ch....@gm...] Sent: 10 June 2009 07:51 To: ssh...@li... Subject: [Ssh-sftp-perl-users] Problem With Net::SSH Hi All , I am trying to do ssh to a machine from my client using the following CODE : use Net::SSH qw(sshopen2); use strict; my $user = "root"; my $host = "changeme"; my $cmd = "ls /root/"; sshopen2("$user\@$host", *READER, *WRITER, "$cmd") || die "ssh: $!"; while (<READER>) { chomp(); print "$_\n"; } close(READER); close(WRITER); When I execute this code it says "Permission denied (publickey,keyboard-interactive)." .Am I missing something here ? The host I am trying to login is a SUSE machine . Please suggest me the solution to get of this problem . Regards, SreeHari Ch |
From: cheerla s. <ch....@gm...> - 2009-06-10 06:52:31
|
Hi All , I am trying to do ssh to a machine from my client using the following CODE : use Net::SSH qw(sshopen2); use strict; my $user = "root"; my $host = "changeme"; my $cmd = "ls /root/"; sshopen2("$user\@$host", *READER, *WRITER, "$cmd") || die "ssh: $!"; while (<READER>) { chomp(); print "$_\n"; } close(READER); close(WRITER); When I execute this code it says "*Permission denied (publickey,keyboard-interactive)*." .Am I missing something here ? The host I am trying to login is a SUSE machine . Please suggest me the solution to get of this problem . Regards, SreeHari Ch |
From: Isaac M. <IM...@pr...> - 2009-05-07 23:03:56
|
Hi there, Thanks in advance. I have a simple perl script that uses the Net::SFTP module. All it has to do is put a file on a remote server. This script works fine from my command line, but it fails from a mod_perl handled web page. Is there some ENV value that needs to be defined? Vitals: kernel: 2.6.18-92.1.22 (CentOS 5.2 - RHEL clone, x86_64) perl: 5.8.8 perl-Net-SSH: 0.08 perl-Net-SFTP: 0.10 Apache: 2.2.3 mod_perl: 2.0.4 Here's the script: -----code snippet----- #!/usr/bin/perl -w use strict; use Net::SFTP; use Net::SSH::Perl; $ENV{'DOCUMENT_ROOT'} = '/var/www/html'; $ENV{'HOME'} = '/home/apache'; $ENV{'USER'} = 'apache'; my $host = "ftp.some-remote-host.com"; my %args = (user => "myUserName", password => "myPassword", ssh_args => [port=>22], debug => "true"); my $sftp = Net::SFTP->new($host, %args) or die "Cannot connect to $@"; print "Successfully Connected.\n"; $sftp->put("localfile.txt", "remotefile.txt"); print "Success.\n"; exit(0); -----end code snippet----- Here's the output that demonstrates the script working as the user "apache" from the command line (the uid that also runs httpd/apache): -----output snippet----- im.corp.local: Reading configuration data /home/apache/.ssh/config im.corp.local: Reading configuration data /etc/ssh_config im.corp.local: Connecting to ftp.some-remote-host.com, port 22. im.corp.local: Remote version string: SSH-2.0-VShell_2_5_1_219 VShell im.corp.local: Remote protocol version 2.0, remote software version VShell_2_5_1_219 VShell im.corp.local: Net::SSH::Perl Version 1.30, protocol version 2.0. .m.corp.local: No compat match: VShell_2_5_1_219 VShell im.corp.local: Connection established. im.corp.local: Sent key-exchange init (KEXINIT), wait response. im.corp.local: Algorithms, c->s: 3des-cbc hmac-sha1 none im.corp.local: Algorithms, s->c: 3des-cbc hmac-sha1 none im.corp.local: Entering Diffie-Hellman Group 1 key exchange. im.corp.local: Sent DH public key, waiting for reply. im.corp.local: Received host key, type 'ssh-dss'. im.corp.local: Host 'ftp.some-remote-host.com' is known and matches the host key. im.corp.local: Computing shared secret key. im.corp.local: Verifying server signature. im.corp.local: Waiting for NEWKEYS message. im.corp.local: Enabling incoming encryption/MAC/compression. im.corp.local: Send NEWKEYS, enable outgoing encryption/MAC/compression. im.corp.local: Sending request for user-authentication service. im.corp.local: Service accepted: ssh-userauth. im.corp.local: Trying empty user-authentication request. im.corp.local: Authentication methods that can continue: password,publickey,gssapi-with-mic. im.corp.local: Next method to try is password. im.corp.local: Trying password authentication. im.corp.local: Login completed, opening dummy shell channel. im.corp.local: channel 0: new [client-session] im.corp.local: Requesting channel_open for channel 0. im.corp.local: channel 0: open confirm rwindow 32768 rmax 16384 im.corp.local: channel 1: new [client-session] im.corp.local: Requesting channel_open for channel 1. im.corp.local: Sending subsystem: sftp im.corp.local: Requesting service subsystem on channel 1. im.corp.local: channel 1: open confirm rwindow 32768 rmax 16384 im.corp.local: sftp: Sending SSH2_FXP_INIT im.corp.local: sftp: Remote version: 3 Connected. im.corp.local: sftp: Sent SSH2_FXP_OPEN I:0 P:file.txt im.corp.local: sftp: Sent message SSH2_FXP_WRITE I:1 O:0 im.corp.local: sftp: In write loop, got 252 offset 0 im.corp.local: sftp: Sent message T:10 I:2 im.corp.local: sftp: Sent message T:4 I:3 -----end output snippet----- Here's the output from the script run under mod_perl when it fails - hangs up at the SSH2_FXP_INIT and times out: -----output snippet----- im.corp.local: Reading configuration data /home/apache/.ssh/config im.corp.local: Reading configuration data /etc/ssh_config im.corp.local: Connecting to ftp.some-remote-host.com, port 22. im.corp.local: Remote version string: SSH-2.0-VShell_2_5_1_219 VShell im.corp.local: Remote protocol version 2.0, remote software version VShell_2_5_1_219 VShell im.corp.local: Net::SSH::Perl Version 1.30, protocol version 2.0. .m.corp.local: No compat match: VShell_2_5_1_219 VShell im.corp.local: Connection established. im.corp.local: Sent key-exchange init (KEXINIT), wait response. im.corp.local: Algorithms, c->s: 3des-cbc hmac-sha1 none im.corp.local: Algorithms, s->c: 3des-cbc hmac-sha1 none im.corp.local: Entering Diffie-Hellman Group 1 key exchange. im.corp.local: Sent DH public key, waiting for reply. im.corp.local: Received host key, type 'ssh-dss'. im.corp.local: Host 'ftp.some-remote-host.com' is known and matches the host key. im.corp.local: Computing shared secret key. im.corp.local: Verifying server signature. im.corp.local: Waiting for NEWKEYS message. im.corp.local: Enabling incoming encryption/MAC/compression. im.corp.local: Send NEWKEYS, enable outgoing encryption/MAC/compression. im.corp.local: Sending request for user-authentication service. im.corp.local: Service accepted: ssh-userauth. im.corp.local: Trying empty user-authentication request. im.corp.local: Authentication methods that can continue: password,publickey,gssapi-with-mic. im.corp.local: Next method to try is password. im.corp.local: Trying password authentication. im.corp.local: Login completed, opening dummy shell channel. im.corp.local: channel 0: new [client-session] im.corp.local: Requesting channel_open for channel 0. im.corp.local: channel 0: open confirm rwindow 32768 rmax 16384 im.corp.local: channel 1: new [client-session] im.corp.local: Requesting channel_open for channel 1. im.corp.local: Sending subsystem: sftp im.corp.local: Requesting service subsystem on channel 1. im.corp.local: channel 1: open confirm rwindow 32768 rmax 16384 im.corp.local: sftp: Sending SSH2_FXP_INIT [Thu May 07 16:34:55 2009] [error] Received disconnect message: 12893: Server disconnect. Session idle time exceeded. \n at /usr/lib/perl5/vendor_perl/5.8.8/Net/SSH/Perl/SSH2.pm line 284\n -----end output snippet----- If I need to direct this to another list, could you enlighten me? I'll follow the mail list, so no need to private message me. Thanks for your help though, -Isaac This message (and any associated files) is intended only for the use of the individual or entity to which it is addressed and may contain information that is confidential, subject to copyright or constitutes a trade secret. If you are not the intended recipient you are hereby notified that any dissemination, copying or distribution of this message, or files associated with this message, is strictly prohibited. If you have received this message in error, please notify us immediately by replying to the message and deleting it from your computer. Messages sent to and from us may be monitored. Internet communications cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. Therefore, we do not accept responsibility for any errors or omissions that are present in this message, or any attachment, that have arisen as a result of e-mail transmission. If verification is required, please request a hard-copy version. Any views or opinions presented are solely those of the author and do not necessarily represent those of the company. |
From: Ron S. <gee...@ya...> - 2009-04-09 09:10:25
|
Hi Nigel, I finally got back into work to try your suggestion. I tried: echo "thePasswd"|sudo -S "whatever command" but that didn't work. I also tried the 'cat' version. But I don't know if I did that one correctly I tried: cat /path/to/somePasswdFile.txt | sudo -S /path/to/some/script.sh Wow! I've tried a number of things to no avail on this one. Maybe its a matter of entering the return character. All I know is when I manually execute the 'sudo' and type in the password from the command line, it always works. So, I'm figuring my troubles have something to with the process I'm trying to submit a password to, expecting input from a shell/command line or I'm missing the carriage return. I'm pretty sure this can be done using Perl, but I'm missing some key info. Hm-mm! ...any other thoughts? Ron Smith gee...@ya... --- On Sun, 4/5/09, Nigel Reed <ni...@sy...> wrote: > From: Nigel Reed <ni...@sy...> > Subject: Re: [Ssh-sftp-perl-users] Everything works except the password... Hm-mm > To: gee...@ya... > Date: Sunday, April 5, 2009, 1:41 PM > I believe to use -S you would need > > echo "mypass"|sudo -S "whatever > command" > > The problem is, a ps -ef will show the password. > > A couple of options is to use the NOPASSWD option for the > sudo command for > this user or store the password locally in a user only > readable file and > then cat the file to the sudo command. > > Ron Smith wrote: > > > > Hi all, > > > > Everything works except the password. What am I > missing/doing wrong? > > > > #!/usr/bin/perl > > > > use warnings; > > use strict; > > > > use Net::SSH::Perl; > > > > my ($host, $user, $pass) = qw(someHost someUser > somePassword); > > my $ps_cmd = 'ps -ef | grep someProcess.sh | grep > -v grep'; > > my $start_cmd = 'sudo -S > /usr/local/bin/someProcess.sh'; > > > > my $ssh = Net::SSH::Perl->new($host); > > $ssh->login($user, $pass); > > my ($stdout, $stderr, $exit) = $ssh->cmd($ps_cmd); > > > > if (!defined $stdout) { > > my $stdin = "password_passed_to_Sudo"; > > print "\n'someProcess.sh' is not > running. An attempt will be made to > > restart it.\n\n"; > > ($stdout, $stderr, $exit) = > $ssh->cmd($start_cmd, $stdin); > > } else { > > print "\n'someProcess.sh' is > running. No action is necessary.\n\n"; > > } > > > > $ssh->cmd("exit"); > > > > It looks like I get connected OK. The grep for the > running process is OK. > > The if statement works fine. I'm running into > trouble getting Sudo to > > accept the password in order to restart the process. > > > > Following is the output from the debugger: > > > > 25==> $ssh->cmd("exit"); > > > DB<8> > > x > > $stdout, > > $stderr, > > $exit, > > $stdin > > 0 ' > > ### Sun Apr 5 17:49:30 GMT 2009 - Establishing SSH > port forwarding > > session ### > > > > > > ### Sun Apr 5 17:49:30 GMT 2009 - SSH port forwarding > session ended ### > > > > ' > > 1 "OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 > 2003\cJdebug1: Reading > > configuration data > /etc/ssh/ssh_config\cM\cJdebug1: Applying options > for > > *\cM\cJdebug1: Connecting to 172.25.101.154 > [172.25.101.154] port > > 22.\cM\cJdebug1: Connection > established.\cM\cJdebug1: permanently_set_uid: > > 0/0\cM\cJdebug1: identity file > /root/.ssh/identity type -1\cM\cJdebug1: > > Remote protocol version 1.99, remote software version > > OpenSSH_3.1p1\cM\cJdebug1: match: > OpenSSH_3.1p1 pat > > > OpenSSH_2.*,OpenSSH_3.0*,OpenSSH_3.1*\cM\cJdebug1: > Local version string > > SSH-1.5-OpenSSH_3.9p1\cM\cJdebug1: Waiting for > server public > > key.\cM\cJdebug1: Received server public key > (768 bits) and host key (1024 > > bits).\cM\cJdebug1: Host > '172.25.101.154' is known and matches the RSA1 > > host key.\cM\cJdebug1: Found key in > /root/.ssh/known_hosts:11\cM\cJdebug1: > > Encryption type: 3des\cM\cJdebug1: Sent > encrypted session > > key.\cM\cJdebug1: Installing crc compensation > attack > > detector.\cM\cJdebug1: Received encrypted > > confirmation.\cM\cJdebug1: Doing challenge > response > > authentication.\cM\cJdebug1: No > challenge.\cM\cJdebug1: Doing password > > authentication.\cM\cJPermission denied, please > try again.\cM\cJPermission > > denied, please try again.\cM\cJPermission > denied.\cM\cJ" > > 2 0 > > 3 undef > > > DB<9> > > q > > > > At zero, $stdout says a session was established for a > time. At 1, $stderr > > gives me the story of what happened. It looks like > $exit gives the 0; I > > think this is correct. But, I'm unsure as to if > $stdin should be undef at > > 3. > > > > Any help would be greatly appreciated. > > > > > > Ron Smith > > gee...@ya... > > > > > ------------------------------------------------------------------------------ > > _______________________________________________ > > Ssh-sftp-perl-users mailing list > > Ssh...@li... > > > https://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users > > > > > -- > Nigel Reed > Candidate for Lieutenant Governor of Marketing 2009-2010 > > President & CEO Sysadmin, Inc > 972 673 4199 http://www.sysadmininc.com > Toastmasters District 50 Vista Division Governor 2008-2009 > Awareness, Attitude and Action bring Achievement! |
From: Jeremy K. <ki...@sc...> - 2009-04-06 17:29:18
|
Charles S Brown wrote: > Here is one of my SSH2 testing scripts. It should provide you with the > routines you're after. If not, let me know and I might be able to help > you further. Cut and paste into your editor of choice... [snip] > # Start a shell on the remote host > $chan->shell(); nope! ->shell doesn't give me the opportunity to get exit codes back from remote commands. -Jeremy |
From: Charles S B. <cb...@jc...> - 2009-04-06 16:16:36
|
Meh, simply attached it... Good luck... Thanks! Chuck e-mail: cb...@jc... office: (972) 431-2030 fax: (972) 531-2030 http://www.linkedin.com/in/chuckbrowntx > -----Original Message----- > From: Charles S Brown > Sent: Monday, April 06, 2009 10:24 AM > To: 'Jeremy Kitchen'; 'ssh...@li...' > Subject: RE: [Ssh-sftp-perl-users] quick question with regard to exec, > take 2 > > Hmmm, some of the formatting became goofy when I pasted it, retry... > > Thanks! > Chuck > > e-mail: cb...@jc... > office: (972) 431-2030 > fax: (972) 531-2030 > http://www.linkedin.com/in/chuckbrowntx > > - - - - - - - - SCRIPT BEGIN - - - - - - - - > > #!/usr/bin/perl > ######################################################################## ## > ##### > # Script Name: test-ssh2.pl > ######################################################################## ## > ##### > #use warnings; > #use strict; > use Net::SSH2; > use Data::Dumper; > > # Version > my $ver = "1.2b"; > > # Cisco Info > my $host = "hostname_or_IP_here"; > my $username = "username_here"; > my $password = "password_here"; > my $command1 = "show users"; > my $command2 = "show ssh"; > my $command3 = "show ntp status"; > > # Display Version > print "VERSION: $ver\n"; > > # Create new SSH2 object > my $ssh2 = Net::SSH2->new(); > > # Enable Debug > #$ssh2->debug(1); > # Create a connection to conduct the SSH2 protocol > $ssh2->connect($host) or die "Unable to connect Host $@ \n"; > > # Determine what type of authentication methods are available > my $authentication_methods = $ssh2->auth_list($username); > print "Valid authentication methods for $host are: > $authentication_methods\n"; > > # Authenticate using a password > $ssh2->auth_password( $username, $password ) or die "Unable to login $@ > \n"; > > #$ssh2->auth(rank => ['none'],username=>$username) or die "Unable to login > $@ \n"; > # Verify we are authenticated - Returns TRUE if authenticated > my $authenticated = $ssh2->auth_ok; > print "Authenticated: $authenticated\n"; > > # Create a channel object (single channel across our established > connection) > my $chan = $ssh2->channel(); > print "DEBUG: After channel\n"; > > # - - - Un-Comment The Routine You Would Like To Execute - - - > # > # The following subroutines work for Cisco and Alcatel > # > # Execute multiple commands utilizing shell method (method A) > #&use_shell_a( $command1, $command2, $command3 ); > # Execute multiple commands utilizing shell method (method B) > #&use_shell_b( $command1, $command2, $command3 ); > # Execute multiple commands utilizing shell method (method C) > #&use_shell_c( $command1, $command2, $command3 ); > # Execute multiple commands _AND_ pattern match utilizing shell method > (method D) > &use_shell_d( $command1, $command2, $command3 ); > > # > # > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > # > # NOTE: On Solaris 9, you must somehow disconnect from the host or the > perl > # script seems to hang. You can do this several ways. > # 1) least graceful, just disconnect the session. > # $ssh2->disconnect(); > # > # 2) more graceful, issue a 'logout' command to your host (or whatever > log-off syntax is required) > # print $chan "logout\n"; > # $chan->close; > # > # 3) fancy, check to see if the session has received an eof from the > host. if not, then > # either perform a graceful logout or just disconnect. > # if (! $chan->eof) { > # print "EOF _NOT_ found attempting graceful disconnect.\n"; > # print $chan "logout\n"; > # } > # > # > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > # > # Disconnect from the host > print "DEBUG: Right before disconnect\n"; > $ssh2->disconnect(); > print "DEBUG: After disconnect\n"; > > # Exit > exit; > > # > # SUBROUTINES > # > sub use_shell_a { > > # Start a shell on the remote host > $chan->shell(); > > # Cycle through each command provided in the sub-routine call > foreach my $command (@_) { > > # Print the command to the defined shell > print $chan "$command\n"; > > # Print the output while there is some data response > print "LINE : $_" while <$chan>; > } > } > > sub use_shell_b { > > # Start a shell on the remote host > $chan->shell(); > > # Cycle through each command provided in the sub-routine call > foreach my $command (@_) { > > # Print the command to the defined shell > print $chan "$command\n"; > > # Print the output while there is some data response > while (<$chan>) { > print "RESP($command) : $_"; > } > } > } > > sub use_shell_c { > > # Start a shell on the remote host > $chan->shell(); > > # Cycle through each command provided in the sub-routine call > foreach my $command (@_) { > > # Print the command to the defined shell > print $chan "$command\n"; > > # Print the output while there is some data response > # Note: This is a more succint version of 'use_shell_b' > print "RESP($command) : $_" while <$chan>; > } > print "complete\n"; > } > > sub use_shell_d { > > # Start a shell on the remote host > $chan->shell(); > > # Cycle through each command provided in the sub-routine call > foreach my $command (@_) { > > # Print the command to the defined shell > print $chan "$command\n"; > > # While there is some data in $chan > while (<$chan>) { > > # Perform a regex match on $_ > if (/$username/) { > > # If a match was found, print the info > print "I located my username while executing '$command', > matched line:\n"; > print "$_\n"; > } > } > } > } > > sub waitfor { > ## waitfor > ## If you want to print any console data gathered while waiting: > ## @returned_data = &waitfor('searchpattern',10); > ## print @returned_data; > ## Where 10 is the timeout in seconds... > ## Otherwise use: > ## &waitfor('searchpattern',10); > ## > my ( $search, $timeout ) = @_; > my @lines; > my $PatternFound = undef; > my $TimedOut = undef; > my @formattedoutput = undef; > $timeout += time(); > until ( $PatternFound || $TimedOut ) { > > # Map some output > @rawoutput = map { $_ } <$chan>; > > # Search for pattern and format return output > foreach $rawline (@rawoutput) { > $rawline =~ s/stty: stdin not a tty//g; ## Remove > unimportant error on Symbol > if ( $rawline =~ /$search/ ) { > $PatternFound = 1; > } > while ( $rawline =~ /\s$/ ) { chop $rawline; } > $formattedline = "$rawline<br>"; > push( @formattedoutput, $formattedline ); > } > > # Check for timeout > if ( time() > $timeout ) { > $TimedOut = 1; > } > } > if ($TimedOut) { > print "ERROR: Timed-Out while waiting for '$search'\n"; > } > ##print "DEBUG: TimedOut = $TimedOut<br>"; > ##print "DEBUG: PatternFound = $PatternFound<br>"; > return (@formattedoutput); > } > > sub print_chan { > @output = map { > while ( $_ =~ /\s$/ ) { chop $_; } > $_ > } <$chan>; > foreach $line (@output) { > $line =~ s/stty: stdin not a tty//g; ## Remove unimportant > error on Symbol > print "\n$line"; > } > } > > sub print_chan_continued { > > # Will print the output of <$chan> until: > # 1) The maximum number of 'press any key' prompts have been > encountered > # 2) A system command prompt is encountered > my $maxpages = 6; > my $pages = 0; > my $endless_loop = 1; > while ($endless_loop) { > @output = map { > while ( $_ =~ /\s$/ ) { chop $_; } > $_ > } <$chan>; > foreach $line (@output) { > $line =~ s/stty: stdin not a tty//g; ## Remove unimportant > error on Symbol > print "\n$line"; > if ( $line =~ /Press any key to continue...or/ && $pages < > $maxpages ) { > > # Gather another page of data > print $chan "\n"; > $pages++; > } > elsif ( $line =~ /Press any key to continue/ && $pages >= > $maxpages ) { > > # Printed the maximum number of pages, (q)uit and return. > print $chan "q\n"; > return; > } > elsif ( $line =~ /.*>.*$|Logging out.../ ) { > > # Matched regular prompt, return. > ##print "DEBUG: matched regular prompt<br>"; > return; > } > } > } > } > > - - - - - - - - SCRIPT END - - - - - - - - |
From: Charles S B. <cb...@jc...> - 2009-04-06 16:02:44
|
Hmmm, some of the formatting became goofy when I pasted it, retry... Thanks! Chuck e-mail: cb...@jc... office: (972) 431-2030 fax: (972) 531-2030 http://www.linkedin.com/in/chuckbrowntx - - - - - - - - SCRIPT BEGIN - - - - - - - - #!/usr/bin/perl ######################################################################## ####### # Script Name: test-ssh2.pl ######################################################################## ####### #use warnings; #use strict; use Net::SSH2; use Data::Dumper; # Version my $ver = "1.2b"; # Cisco Info my $host = "hostname_or_IP_here"; my $username = "username_here"; my $password = "password_here"; my $command1 = "show users"; my $command2 = "show ssh"; my $command3 = "show ntp status"; # Display Version print "VERSION: $ver\n"; # Create new SSH2 object my $ssh2 = Net::SSH2->new(); # Enable Debug #$ssh2->debug(1); # Create a connection to conduct the SSH2 protocol $ssh2->connect($host) or die "Unable to connect Host $@ \n"; # Determine what type of authentication methods are available my $authentication_methods = $ssh2->auth_list($username); print "Valid authentication methods for $host are: $authentication_methods\n"; # Authenticate using a password $ssh2->auth_password( $username, $password ) or die "Unable to login $@ \n"; #$ssh2->auth(rank => ['none'],username=>$username) or die "Unable to login $@ \n"; # Verify we are authenticated - Returns TRUE if authenticated my $authenticated = $ssh2->auth_ok; print "Authenticated: $authenticated\n"; # Create a channel object (single channel across our established connection) my $chan = $ssh2->channel(); print "DEBUG: After channel\n"; # - - - Un-Comment The Routine You Would Like To Execute - - - # # The following subroutines work for Cisco and Alcatel # # Execute multiple commands utilizing shell method (method A) #&use_shell_a( $command1, $command2, $command3 ); # Execute multiple commands utilizing shell method (method B) #&use_shell_b( $command1, $command2, $command3 ); # Execute multiple commands utilizing shell method (method C) #&use_shell_c( $command1, $command2, $command3 ); # Execute multiple commands _AND_ pattern match utilizing shell method (method D) &use_shell_d( $command1, $command2, $command3 ); # # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # NOTE: On Solaris 9, you must somehow disconnect from the host or the perl # script seems to hang. You can do this several ways. # 1) least graceful, just disconnect the session. # $ssh2->disconnect(); # # 2) more graceful, issue a 'logout' command to your host (or whatever log-off syntax is required) # print $chan "logout\n"; # $chan->close; # # 3) fancy, check to see if the session has received an eof from the host. if not, then # either perform a graceful logout or just disconnect. # if (! $chan->eof) { # print "EOF _NOT_ found attempting graceful disconnect.\n"; # print $chan "logout\n"; # } # # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Disconnect from the host print "DEBUG: Right before disconnect\n"; $ssh2->disconnect(); print "DEBUG: After disconnect\n"; # Exit exit; # # SUBROUTINES # sub use_shell_a { # Start a shell on the remote host $chan->shell(); # Cycle through each command provided in the sub-routine call foreach my $command (@_) { # Print the command to the defined shell print $chan "$command\n"; # Print the output while there is some data response print "LINE : $_" while <$chan>; } } sub use_shell_b { # Start a shell on the remote host $chan->shell(); # Cycle through each command provided in the sub-routine call foreach my $command (@_) { # Print the command to the defined shell print $chan "$command\n"; # Print the output while there is some data response while (<$chan>) { print "RESP($command) : $_"; } } } sub use_shell_c { # Start a shell on the remote host $chan->shell(); # Cycle through each command provided in the sub-routine call foreach my $command (@_) { # Print the command to the defined shell print $chan "$command\n"; # Print the output while there is some data response # Note: This is a more succint version of 'use_shell_b' print "RESP($command) : $_" while <$chan>; } print "complete\n"; } sub use_shell_d { # Start a shell on the remote host $chan->shell(); # Cycle through each command provided in the sub-routine call foreach my $command (@_) { # Print the command to the defined shell print $chan "$command\n"; # While there is some data in $chan while (<$chan>) { # Perform a regex match on $_ if (/$username/) { # If a match was found, print the info print "I located my username while executing '$command', matched line:\n"; print "$_\n"; } } } } sub waitfor { ## waitfor ## If you want to print any console data gathered while waiting: ## @returned_data = &waitfor('searchpattern',10); ## print @returned_data; ## Where 10 is the timeout in seconds... ## Otherwise use: ## &waitfor('searchpattern',10); ## my ( $search, $timeout ) = @_; my @lines; my $PatternFound = undef; my $TimedOut = undef; my @formattedoutput = undef; $timeout += time(); until ( $PatternFound || $TimedOut ) { # Map some output @rawoutput = map { $_ } <$chan>; # Search for pattern and format return output foreach $rawline (@rawoutput) { $rawline =~ s/stty: stdin not a tty//g; ## Remove unimportant error on Symbol if ( $rawline =~ /$search/ ) { $PatternFound = 1; } while ( $rawline =~ /\s$/ ) { chop $rawline; } $formattedline = "$rawline<br>"; push( @formattedoutput, $formattedline ); } # Check for timeout if ( time() > $timeout ) { $TimedOut = 1; } } if ($TimedOut) { print "ERROR: Timed-Out while waiting for '$search'\n"; } ##print "DEBUG: TimedOut = $TimedOut<br>"; ##print "DEBUG: PatternFound = $PatternFound<br>"; return (@formattedoutput); } sub print_chan { @output = map { while ( $_ =~ /\s$/ ) { chop $_; } $_ } <$chan>; foreach $line (@output) { $line =~ s/stty: stdin not a tty//g; ## Remove unimportant error on Symbol print "\n$line"; } } sub print_chan_continued { # Will print the output of <$chan> until: # 1) The maximum number of 'press any key' prompts have been encountered # 2) A system command prompt is encountered my $maxpages = 6; my $pages = 0; my $endless_loop = 1; while ($endless_loop) { @output = map { while ( $_ =~ /\s$/ ) { chop $_; } $_ } <$chan>; foreach $line (@output) { $line =~ s/stty: stdin not a tty//g; ## Remove unimportant error on Symbol print "\n$line"; if ( $line =~ /Press any key to continue...or/ && $pages < $maxpages ) { # Gather another page of data print $chan "\n"; $pages++; } elsif ( $line =~ /Press any key to continue/ && $pages >= $maxpages ) { # Printed the maximum number of pages, (q)uit and return. print $chan "q\n"; return; } elsif ( $line =~ /.*>.*$|Logging out.../ ) { # Matched regular prompt, return. ##print "DEBUG: matched regular prompt<br>"; return; } } } } - - - - - - - - SCRIPT END - - - - - - - - |
From: Charles S B. <cb...@jc...> - 2009-04-06 16:02:40
|
Here is one of my SSH2 testing scripts. It should provide you with the routines you're after. If not, let me know and I might be able to help you further. Cut and paste into your editor of choice... Thanks! Chuck e-mail: cb...@jc... http://www.linkedin.com/in/chuckbrowntx - - - - - - - - SCRIPT BEGIN - - - - - - - - #!/usr/bin/perl ######################################################################## ####### # Script Name: test-ssh2.pl ######################################################################## ####### #use warnings; #use strict; use Net::SSH2; use Data::Dumper; # Version my $ver = "1.2b"; # Cisco Info my $host = "hostname_or_IP_here"; my $username = "username_here"; my $password = "password_here"; my $command1 = "show users"; my $command2 = "show ssh"; my $command3 = "show ntp status"; # Display Version print "VERSION: $ver\n"; # Create new SSH2 object my $ssh2 = Net::SSH2->new(); # Enable Debug #$ssh2->debug(1); # Create a connection to conduct the SSH2 protocol $ssh2->connect($host) or die "Unable to connect Host $@ \n"; # Determine what type of authentication methods are available my $authentication_methods = $ssh2->auth_list($username); print "Valid authentication methods for $host are: $authentication_methods\n"; # Authenticate using a password $ssh2->auth_password( $username, $password ) or die "Unable to login $@ \n"; #$ssh2->auth(rank => ['none'],username=>$username) or die "Unable to login $@ \n"; # Verify we are authenticated - Returns TRUE if authenticated my $authenticated = $ssh2->auth_ok; print "Authenticated: $authenticated\n"; # Create a channel object (single channel across our established connection) my $chan = $ssh2->channel(); print "DEBUG: After channel\n"; # - - - Un-Comment The Routine You Would Like To Execute - - - # # The following subroutines work for Cisco and Alcatel # # Execute multiple commands utilizing shell method (method A) #&use_shell_a( $command1, $command2, $command3 ); # Execute multiple commands utilizing shell method (method B) #&use_shell_b( $command1, $command2, $command3 ); # Execute multiple commands utilizing shell method (method C) #&use_shell_c( $command1, $command2, $command3 ); # Execute multiple commands _AND_ pattern match utilizing shell method (method D) &use_shell_d( $command1, $command2, $command3 ); # # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # NOTE: On Solaris 9, you must somehow disconnect from the host or the perl # script seems to hang. You can do this several ways. # 1) least graceful, just disconnect the session. # $ssh2->disconnect(); # # 2) more graceful, issue a 'logout' command to your host (or whatever log-off syntax is required) # print $chan "logout\n"; # $chan->close; # # 3) fancy, check to see if the session has received an eof from the host. if not, then # either perform a graceful logout or just disconnect. # if (! $chan->eof) { # print "EOF _NOT_ found attempting graceful disconnect.\n"; # print $chan "logout\n"; # } # # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Disconnect from the host print "DEBUG: Right before disconnect\n"; $ssh2->disconnect(); print "DEBUG: After disconnect\n"; # Exit exit; # # SUBROUTINES # sub use_shell_a { # Start a shell on the remote host $chan->shell(); # Cycle through each command provided in the sub-routine call foreach my $command (@_) { # Print the command to the defined shell print $chan "$command\n"; # Print the output while there is some data response print "LINE : $_" while <$chan>; } } sub use_shell_b { # Start a shell on the remote host $chan->shell(); # Cycle through each command provided in the sub-routine call foreach my $command (@_) { # Print the command to the defined shell print $chan "$command\n"; # Print the output while there is some data response while (<$chan>) { print "RESP($command) : $_"; } } } sub use_shell_c { # Start a shell on the remote host $chan->shell(); # Cycle through each command provided in the sub-routine call foreach my $command (@_) { # Print the command to the defined shell print $chan "$command\n"; # Print the output while there is some data response # Note: This is a more succint version of 'use_shell_b' print "RESP($command) : $_" while <$chan>; } print "complete\n"; } sub use_shell_d { # Start a shell on the remote host $chan->shell(); # Cycle through each command provided in the sub-routine call foreach my $command (@_) { # Print the command to the defined shell print $chan "$command\n"; # While there is some data in $chan while (<$chan>) { # Perform a regex match on $_ if (/$username/) { # If a match was found, print the info print "I located my username while executing '$command', matched line:\n"; print "$_\n"; } } } } sub waitfor { ## waitfor ## If you want to print any console data gathered while waiting: ## @returned_data = &waitfor('searchpattern',10); ## print @returned_data; ## Where 10 is the timeout in seconds... ## Otherwise use: ## &waitfor('searchpattern',10); ## my ( $search, $timeout ) = @_; my @lines; my $PatternFound = undef; my $TimedOut = undef; my @formattedoutput = undef; $timeout += time(); until ( $PatternFound || $TimedOut ) { # Map some output @rawoutput = map { $_ } <$chan>; # Search for pattern and format return output foreach $rawline (@rawoutput) { $rawline =~ s/stty: stdin not a tty//g; ## Remove unimportant error on Symbol if ( $rawline =~ /$search/ ) { $PatternFound = 1; } while ( $rawline =~ /\s$/ ) { chop $rawline; } $formattedline = "$rawline<br>"; push( @formattedoutput, $formattedline ); } # Check for timeout if ( time() > $timeout ) { $TimedOut = 1; } } if ($TimedOut) { print "ERROR: Timed-Out while waiting for '$search'\n"; } ##print "DEBUG: TimedOut = $TimedOut<br>"; ##print "DEBUG: PatternFound = $PatternFound<br>"; return (@formattedoutput); } sub print_chan { @output = map { while ( $_ =~ /\s$/ ) { chop $_; } $_ } <$chan>; foreach $line (@output) { $line =~ s/stty: stdin not a tty//g; ## Remove unimportant error on Symbol print "\n$line"; } } sub print_chan_continued { # Will print the output of <$chan> until: # 1) The maximum number of 'press any key' prompts have been encountered # 2) A system command prompt is encountered my $maxpages = 6; my $pages = 0; my $endless_loop = 1; while ($endless_loop) { @output = map { while ( $_ =~ /\s$/ ) { chop $_; } $_ } <$chan>; foreach $line (@output) { $line =~ s/stty: stdin not a tty//g; ## Remove unimportant error on Symbol print "\n$line"; if ( $line =~ /Press any key to continue...or/ && $pages < $maxpages ) { # Gather another page of data print $chan "\n"; $pages++; } elsif ( $line =~ /Press any key to continue/ && $pages >= $maxpages ) { # Printed the maximum number of pages, (q)uit and return. print $chan "q\n"; return; } elsif ( $line =~ /.*>.*$|Logging out.../ ) { # Matched regular prompt, return. ##print "DEBUG: matched regular prompt<br>"; return; } } } } - - - - - - - - SCRIPT END - - - - - - - - > -----Original Message----- > From: Jeremy Kitchen [mailto:ki...@sc...] > Sent: Thursday, April 02, 2009 12:47 PM > To: ssh...@li... > Subject: [Ssh-sftp-perl-users] quick question with regard to exec, take 2 > > I'm trying to write a quick program which will execute a series of > commands on the remote system and get each individual exit status back > from the commands. > > It appears the way to go about doing this is to create a new channel, > exec, get the exit status, destroy the channel, exec, get the exit > status, etc. > > However, I *also* want to grab the output of these commands (stdout and > stderr) in real time, so I'm trying to use poll. > > Now, I could be going about this completely the wrong way. If I am, > please let me know :) > > $channel->shell doesn't seem like it fits for me as I don't think I can > get the exit statuses back from the remote commands being run. > > Here's a bit of what I have so far (which isn't working): > > my $channel = $ssh->channel; > > $channel->exec("sleep 5 && echo 'moo' && sleep 1"); > > print "\n"; > while (1) { > print "loop\n"; > my @poll = ({handle => $channel, events => ['in','err']}); > if ($ssh->poll(500, \@poll)) { > # handle events > } > > print Dumper($poll[0]->{revents}); > } > > > everything is all well and good until the command finishes (after the > sleep 5), when polling completely blocks. Nothing further ever happens. > If I kill the remote sshd process handling the connection (the > user@notty process) then it returns these events: > $VAR1 = { > 'in' => 1, > 'value' => 129, > 'listener_closed' => 1, > 'channel_closed' => 1 > }; > > > Is there some step I'm missing to make this work how I want? > > -Jeremy |
From: Ron S. <gee...@ya...> - 2009-04-05 18:35:44
|
Hi all, Everything works except the password. What am I missing/doing wrong? #!/usr/bin/perl use warnings; use strict; use Net::SSH::Perl; my ($host, $user, $pass) = qw(someHost someUser somePassword); my $ps_cmd = 'ps -ef | grep someProcess.sh | grep -v grep'; my $start_cmd = 'sudo -S /usr/local/bin/someProcess.sh'; my $ssh = Net::SSH::Perl->new($host); $ssh->login($user, $pass); my ($stdout, $stderr, $exit) = $ssh->cmd($ps_cmd); if (!defined $stdout) { my $stdin = "password_passed_to_Sudo"; print "\n'someProcess.sh' is not running. An attempt will be made to restart it.\n\n"; ($stdout, $stderr, $exit) = $ssh->cmd($start_cmd, $stdin); } else { print "\n'someProcess.sh' is running. No action is necessary.\n\n"; } $ssh->cmd("exit"); It looks like I get connected OK. The grep for the running process is OK. The if statement works fine. I'm running into trouble getting Sudo to accept the password in order to restart the process. Following is the output from the debugger: 25==> $ssh->cmd("exit"); DB<8> x $stdout, $stderr, $exit, $stdin 0 ' ### Sun Apr 5 17:49:30 GMT 2009 - Establishing SSH port forwarding session ### ### Sun Apr 5 17:49:30 GMT 2009 - SSH port forwarding session ended ### ' 1 "OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 2003\cJdebug1: Reading configuration data /etc/ssh/ssh_config\cM\cJdebug1: Applying options for *\cM\cJdebug1: Connecting to 172.25.101.154 [172.25.101.154] port 22.\cM\cJdebug1: Connection established.\cM\cJdebug1: permanently_set_uid: 0/0\cM\cJdebug1: identity file /root/.ssh/identity type -1\cM\cJdebug1: Remote protocol version 1.99, remote software version OpenSSH_3.1p1\cM\cJdebug1: match: OpenSSH_3.1p1 pat OpenSSH_2.*,OpenSSH_3.0*,OpenSSH_3.1*\cM\cJdebug1: Local version string SSH-1.5-OpenSSH_3.9p1\cM\cJdebug1: Waiting for server public key.\cM\cJdebug1: Received server public key (768 bits) and host key (1024 bits).\cM\cJdebug1: Host '172.25.101.154' is known and matches the RSA1 host key.\cM\cJdebug1: Found key in /root/.ssh/known_hosts:11\cM\cJdebug1: Encryption type: 3des\cM\cJdebug1: Sent encrypted session key.\cM\cJdebug1: Installing crc compensation attack detector.\cM\cJdebug1: Received encrypted confirmation.\cM\cJdebug1: Doing challenge response authentication.\cM\cJdebug1: No challenge.\cM\cJdebug1: Doing password authentication.\cM\cJPermission denied, please try again.\cM\cJPermission denied, please try again.\cM\cJPermission denied.\cM\cJ" 2 0 3 undef DB<9> q At zero, $stdout says a session was established for a time. At 1, $stderr gives me the story of what happened. It looks like $exit gives the 0; I think this is correct. But, I'm unsure as to if $stdin should be undef at 3. Any help would be greatly appreciated. Ron Smith gee...@ya... |
From: Thierry C. <thi...@gm...> - 2009-04-04 21:27:58
|
Jeremy Kitchen a écrit : > Thierry CHICH wrote: > >> Jeremy Kitchen a écrit : >> >>> I'm trying to write a quick program which will execute a series of >>> commands on the remote system and get each individual exit status back >>> from the commands. >>> >>> It appears the way to go about doing this is to create a new channel, >>> exec, get the exit status, destroy the channel, exec, get the exit >>> status, etc. >>> >>> However, I *also* want to grab the output of these commands (stdout and >>> stderr) in real time, so I'm trying to use poll. >>> >>> Now, I could be going about this completely the wrong way. If I am, >>> please let me know :) >>> >>> >>> >> I don't know if you are going the wrong way. However, I don't >> understand why you are not using >> ( $out, $err, $exit ) = $ssh->cmd( "$cmd" ); ? >> >> You can even execute a complete script shell using sthis syntax: >> >> ( $out, $err, $exit ) = $ssh->cmd( "bash", "$myscrypt" ); >> Isn't it simpler ? >> >> > > I'm not using Net::SSH::Perl, I'm using Net::SSH2. Net::SSH::Perl can't > connect to several of our machines, but Net::SSH2 can. Also, using > Net::SSH2's ->cmd method still doesn't give me 'real time' reading of > the outputs. I *do* want to do something like what ->cmd does > eventually, for really stupid easy stuff where we don't really care > about the output until it's done (or commands that are *really* quick) > but in the mean time I'm trying to get the realtime stuff working. > > -Jeremy > Ok. I should have seen that the syntax was not coming form the Net::SSH::Perl I have not use Net::SSH2 as you have : for me, there is a big lack to the libssh2 library, and it is the lack of ssh-agent support. So it could be a stupid suggestion, but have you try to put $channel->blocking(0); at the beginning of your script ? I remember I had problem without this line. > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------------ > > ------------------------------------------------------------------------ > > _______________________________________________ > Ssh-sftp-perl-users mailing list > Ssh...@li... > https://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users > |
From: Jeremy K. <ki...@sc...> - 2009-04-03 21:58:08
|
Thierry CHICH wrote: > Jeremy Kitchen a écrit : >> I'm trying to write a quick program which will execute a series of >> commands on the remote system and get each individual exit status back >> from the commands. >> >> It appears the way to go about doing this is to create a new channel, >> exec, get the exit status, destroy the channel, exec, get the exit >> status, etc. >> >> However, I *also* want to grab the output of these commands (stdout and >> stderr) in real time, so I'm trying to use poll. >> >> Now, I could be going about this completely the wrong way. If I am, >> please let me know :) >> >> > I don't know if you are going the wrong way. However, I don't > understand why you are not using > ( $out, $err, $exit ) = $ssh->cmd( "$cmd" ); ? > > You can even execute a complete script shell using sthis syntax: > > ( $out, $err, $exit ) = $ssh->cmd( "bash", "$myscrypt" ); > Isn't it simpler ? > I'm not using Net::SSH::Perl, I'm using Net::SSH2. Net::SSH::Perl can't connect to several of our machines, but Net::SSH2 can. Also, using Net::SSH2's ->cmd method still doesn't give me 'real time' reading of the outputs. I *do* want to do something like what ->cmd does eventually, for really stupid easy stuff where we don't really care about the output until it's done (or commands that are *really* quick) but in the mean time I'm trying to get the realtime stuff working. -Jeremy |
From: Jeremy K. <ki...@sc...> - 2009-04-03 21:56:19
|
Stefan Adling wrote: > my $ssh = Net::SSH::Perl->new( "rmote_machine"); sorry, I must have failed to mention that I'm using Net::SSH2, not Net::SSH::Perl -Jeremy |
From: Thierry C. <thi...@gm...> - 2009-04-03 21:06:18
|
Jeremy Kitchen a écrit : > I'm trying to write a quick program which will execute a series of > commands on the remote system and get each individual exit status back > from the commands. > > It appears the way to go about doing this is to create a new channel, > exec, get the exit status, destroy the channel, exec, get the exit > status, etc. > > However, I *also* want to grab the output of these commands (stdout and > stderr) in real time, so I'm trying to use poll. > > Now, I could be going about this completely the wrong way. If I am, > please let me know :) > > I don't know if you are going the wrong way. However, I don't understand why you are not using ( $out, $err, $exit ) = $ssh->cmd( "$cmd" ); ? You can even execute a complete script shell using sthis syntax: ( $out, $err, $exit ) = $ssh->cmd( "bash", "$myscrypt" ); Isn't it simpler ? |
From: Jeremy K. <ki...@sc...> - 2009-04-02 18:05:57
|
I'm trying to write a quick program which will execute a series of commands on the remote system and get each individual exit status back from the commands. It appears the way to go about doing this is to create a new channel, exec, get the exit status, destroy the channel, exec, get the exit status, etc. However, I *also* want to grab the output of these commands (stdout and stderr) in real time, so I'm trying to use poll. Now, I could be going about this completely the wrong way. If I am, please let me know :) $channel->shell doesn't seem like it fits for me as I don't think I can get the exit statuses back from the remote commands being run. Here's a bit of what I have so far (which isn't working): my $channel = $ssh->channel; $channel->exec("sleep 5 && echo 'moo' && sleep 1"); print "\n"; while (1) { print "loop\n"; my @poll = ({handle => $channel, events => ['in','err']}); if ($ssh->poll(500, \@poll)) { # handle events } print Dumper($poll[0]->{revents}); } everything is all well and good until the command finishes (after the sleep 5), when polling completely blocks. Nothing further ever happens. If I kill the remote sshd process handling the connection (the user@notty process) then it returns these events: $VAR1 = { 'in' => 1, 'value' => 129, 'listener_closed' => 1, 'channel_closed' => 1 }; Is there some step I'm missing to make this work how I want? -Jeremy |
From: Vikas P. <vik...@ya...> - 2009-04-02 05:24:45
|
Hello I need to write a perl script that is used to count the number of pipe symbol (|) in a file. Can anyone let me know how it can be done. Thanks and Regards Vikas Poonia |