Net::Scp
I am using the code below. When I run the script if I run it for just one file then everything works fine. It asks me for my passpharase and copies perfectly. If I uncomment both scp -> iscp statements and run the script it asks me for the first one and then locks on the question proceed [y/N] for the second I have to kill the cmd window to get back. Any thoughts? #!/usr/bin/perl use strict; use warnings; use Net::SCP qw / scp iscp /; my $leases = 'hylafax:/var/state/dhcp/dhcpd.leases'; my $access = 'hylafax:/usr/local/squid/var/logs/access.log'; my $scp = Net::SCP -> new ( 'hylafax', 'pdk' ); print "Getting Leases File\n"; $scp -> iscp ( $leases, 'scpleases.txt' ); print "Getting Access File\n"; $scp -> iscp ( $access, 'scpaccess.txt' ); Paul Kraus --- PEL Supply Company Network Administrator --- 800 321-1264 Toll Free 216 267-5775 Voice 216 267-6176 Fax www.pelsupply.com --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
Net::SCP
Hi, I installed Net::SCP as I was reminded of the module in a recent post. I need to copy files from one server to another. I generated ssh-keys for a user and I can use scp test.txt myserver:/home/somedude/mytest.txt without passwords when I su to that user but when I run the script as myself it doesn't work. # $DEBUG = 1; scp /home/somedude/fo.txt [EMAIL PROTECTED]:/home/images/my170px.jpg 256 lost connection Is this behaviour by design? The script was meant to run as the httpd user. Is it recommended to set-up ssh-keys for that account? That account is set with nologin. I think I would have to enable it to make the scp work. I can't imagine that's recommended! Should I be thinking about another route for this? Thanx and sorry if I have strayed OT. Dp. #!/usr/local/bin/perl use Net::SCP (scp); use strict; use warnings; my $file = 'fo.txt'; my $scp = Net::SCP->new("myserver"); $scp->login('somedude') or warn $?, " ", $scp->{errstr}; $scp->put($file,$remote) or warn $?, " ", $scp->{errstr}; $scp->quit; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Net::SCP
Did anybody get Net::SCP to work in an NT env machine? I tried use Net::SCP qw(scp iscp); ... ... $scp = Net::SCP->new( $hostname, $username ) or die "foo"; scp("$username\@$hostname\:$remote_dir$filename", "c:\\$filename") or die "bar"; but the program is just hanging without any output or prompts or errors -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Net::SCP::Expect
Would someone mind telling me what I am doing wrong here please. I am trying to tie the SCP Expect module into a backup script I put together, but it keeps failing. I stripped out all but the SCP example code and it still generates an error from the module. I verified my login, directory and filenames were correct by sending the file manually. I am running Perl v5.8.0, Expect-1.14, and Net-SCP-Expect-0.10 ===The script=== #!/usr/bin/perl -w use strict; use Net::SCP::Expect; my $host = "host.whatever"; my $user = "josem"; my $pwd = "password"; my $scp = Net::SCP::Expect->new(host=>$host,user=>$user,password=>$pwd); $scp->scp("[backup.tar]","[/home/josem]"); exit 0; ===The error=== josem $./script3.pl at /usr/lib/perl5/site_perl/5.8.0/Expect.pm line 730ease try again. ===Line 730 from Expect.pm=== 725 if ($#{$pattern} > 3) { 726 # call with parameters if given 727 $exp_cont = &{$pattern->[3]}($exp, 728 @{$pattern}[4..$#{$pattern}]); 729 } else { 730 $exp_cont = &{$pattern->[3]}($exp); 731 } Any help would be greatly appreciated! Thanks, Jose
Re: Net::Scp
Paul Kraus wrote: I am using the code below. When I run the script if I run it for just one file then everything works fine. It asks me for my passpharase and copies perfectly. If I uncomment both scp -> iscp statements and run the script it asks me for the first one and then locks on the question proceed [y/N] for the second I have to kill the cmd window to get back. Any thoughts? #!/usr/bin/perl use strict; use warnings; use Net::SCP qw / scp iscp /; my $leases = 'hylafax:/var/state/dhcp/dhcpd.leases'; my $access = 'hylafax:/usr/local/squid/var/logs/access.log'; my $scp = Net::SCP -> new ( 'hylafax', 'pdk' ); print "Getting Leases File\n"; $scp -> iscp ( $leases, 'scpleases.txt' ); print "Getting Access File\n"; $scp -> iscp ( $access, 'scpaccess.txt' ); What system are you running this on? What is the system you are connecting to? Can you clarify where it is hanging, is it on the proceed question for the first or second file? Is the first file being copied successfully? I suspect it is a problem with the 'waitpid' that is being done to reap the process, that or the fact that it is using an Open3 call but doing nothing with the writer/reader pipes. I don't normally do this, but I am tempted to say you shouldn't use the module. In general I don't like shelling out, especially when IPC is involved, and I am not sure the module does a good enough job handling the possibilities of deadlock with respect to Open3 (which is maybe what you are seeing). You also mention entering a password which it says not to do, I am not quite sure how that is even working and this might also be the problem, as the Perl program isn't prompting for one, it is the scp doing that, but if the scp's pipes are being handled by the Open3 then the password is never getting there, which is curious to say the least. But these issues aside, the fact that there is a parameter listed in the POD for 'interactive' mode which is passed through to set $self->{'interactive'} in the constructor but then it is $self->{'interact'} that is actually called for in the source of scp indicates a general lack of attention to detail within what is relatively simple source, the fact that it could be misdocumented really scares me... However that doesn't help you much I suspect. Two options appear to me, if you don't mind the dependency hell of Net::SSH::Perl, and if all out speed isn't an issue, you might check out Net::SFTP. I have had very good luck with it, 1 issue aside (which has to do with memory leaking in Math::PARI for long running (aka 3+ hours) scripts). Alternatively you could roll your own 'scp' wrapper using Expect (which I seldom advocate but haven't seen a better option for calling scp yet). In any case, if you are not using key based authentication and intend to run this interactively why both with the Perl script at all? http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
Re: Net::SCP
Dermot пишет: Hi, I installed Net::SCP as I was reminded of the module in a recent post. I need to copy files from one server to another. I generated ssh-keys for a user and I can use scp test.txt myserver:/home/somedude/mytest.txt without passwords when I su to that user but when I run the script as myself it doesn't work. # $DEBUG = 1; scp /home/somedude/fo.txt [EMAIL PROTECTED]:/home/images/my170px.jpg 256 lost connection You should generate ssh keys for the user which runs your script. [EMAIL PROTECTED] ssh-keygen -t rsa then add your key from /home/dermot/.ssh/id_rsa.pub (I don't remember exact file names) to the end of /home/remote_user/.ssh/authorized_keys 1) $ ssh-keygen -t rsa 2) $ ssh-copy-id -i ~/.ssh/id_rsa [EMAIL PROTECTED] 3) $ scp ~/.ssh/id_rsa.pub [EMAIL PROTECTED] 4) $ ssh [EMAIL PROTECTED] 5) remote$ mkdir -p ~/.ssh; chmod 711 ~/.ssh remote$ cat ~/id_rsa.pub >> ~/.ssh/authorized_keys 6) remote$ chmod 600 ~/.ssh/authorized_keys 7) remote$ rm ~/id_rsa.pub -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Net::SCP
2008/9/22 Vyacheslav Karamov <[EMAIL PROTECTED]>: > Dermot пишет: >> >> Hi, >> >> I installed Net::SCP as I was reminded of the module in a recent post. >> >> I need to copy files from one server to another. I generated ssh-keys >> for a user and I can use >> >> scp test.txt myserver:/home/somedude/mytest.txt >> >> without passwords when I su to that user but when I run the script as >> myself it doesn't work. >> >> # $DEBUG = 1; >> scp /home/somedude/fo.txt [EMAIL PROTECTED]:/home/images/my170px.jpg >> 256 lost connection >> >> > > You should generate ssh keys for the user which runs your script. The script would run as the httpd user and that account is set as /sbin/nologin. My gut feeling is that it would be considered bad practise to enable a shell on this account and install ssh keys for it. Does anyone have an opinion on that? Thanx, Dp.
Fw: Net::SCP::Expect
Sorry if this comes across twice. It bounced back the first time... Would someone mind telling me what I am doing wrong here please. I am trying to tie the SCP Expect module into a backup script I put together, but it keeps failing. I stripped out all but the SCP example code and it still generates an error from the module. I verified my login, directory and filenames were correct by sending the file manually. I am running Perl v5.8.0, Expect-1.14, and Net-SCP-Expect-0.10 #The Script #!/usr/bin/perl -w use strict; use Net::SCP::Expect; my $host = "host.whatever"; my $user = "josem"; my $pwd = "password"; my $scp = Net::SCP::Expect->new(host=>$host,user=>$user,password=>$pwd); $scp->scp("[backup.tar]","[/home/josem]"); exit 0; #The error josem $./script3.pl at /usr/lib/perl5/site_perl/5.8.0/Expect.pm line 730ease try again. #Line 730 from Expect.pm 725 if ($#{$pattern} > 3) { 726 # call with parameters if given 727 $exp_cont = &{$pattern->[3]}($exp, 728 @{$pattern}[4..$#{$pattern}]); 729 } else { 730 $exp_cont = &{$pattern->[3]}($exp); 731 } Any help would be greatly appreciated! Thanks, Jose
Net -> SCP - errstr uninitialized
Code #!/usr/bin/perl use strict; use warnings; &dhcpd; sub dhcpd { use Text::DHCPparse; use Net::SCP qw( scp iscp ); my $scp = Net::SCP -> new( 'hylafax', 'pkraus' ); $scp -> get ( 'dhcpd.leases' ) or die $scp->{errstr}; print "hello\n"; } Error - Use of uninitilazed value in die at C:\Documents and Settings\pdk\My Documents\perl code\squidlogs\squid.pl line12. Died at C:\... line 12 Paul Kraus --- PEL Supply Company Network Administrator --- 800 321-1264 Toll Free 216 267-5775 Voice 216 267-6176 Fax www.pelsupply.com --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
Re: Fw: Net::SCP::Expect
Jose Malacara wrote: > Sorry if this comes across twice. It bounced back the first time... > > Would someone mind telling me what I am doing wrong here please. I am trying to tie > the SCP Expect module into a backup script I put together, but it keeps failing. I > stripped out all but the SCP example code and it still generates an error from the > module. I verified my login, directory and filenames were correct by sending the > file manually. > > I am running Perl v5.8.0, Expect-1.14, and Net-SCP-Expect-0.10 > > use Net::SCP::Expect; > my $host = "host.whatever"; > ... > #The error > josem $./script3.pl > at /usr/lib/perl5/site_perl/5.8.0/Expect.pm line 730ease try again. > > #Line 730 from Expect.pm > 725 if ($#{$pattern} > 3) { > 726 # call with parameters if given > 727 $exp_cont = &{$pattern->[3]}($exp, > 728 @{$pattern}[4..$#{$pattern}]); > 729 } else { > 730 $exp_cont = &{$pattern->[3]}($exp); > 731 } My guess is thatthis is a malformed host name. It should be in the form. hostname.ext where ext is the top-level domain, such as .com, .net, .org, .etc. Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Fw: Net::SCP::Expect
I am using a proper hostname, and have even tried several different hosts. I just left it out of the example I sent to the list. I verified all the login, hostname, filename, password, etc by scp the file manually. I have even loaded the modules on another machine and I still get the same error. - Original Message - From: "R. Joseph Newton" <[EMAIL PROTECTED]> To: "Jose Malacara" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Wednesday, October 01, 2003 7:49 AM Subject: Re: Fw: Net::SCP::Expect > Jose Malacara wrote: > > > Sorry if this comes across twice. It bounced back the first time... > > > > Would someone mind telling me what I am doing wrong here please. I am trying to tie the SCP Expect module into a backup script I put together, but it keeps failing. I stripped out all but the SCP example code and it still generates an error from the module. I verified my login, directory and filenames were correct by sending the file manually. > > > > I am running Perl v5.8.0, Expect-1.14, and Net-SCP-Expect-0.10 > > > > use Net::SCP::Expect; > > my $host = "host.whatever"; > > ... > > #The error > > josem $./script3.pl > > at /usr/lib/perl5/site_perl/5.8.0/Expect.pm line 730ease try again. > > > > #Line 730 from Expect.pm > > 725 if ($#{$pattern} > 3) { > > 726 # call with parameters if given > > 727 $exp_cont = &{$pattern->[3]}($exp, > > 728 @{$pattern}[4..$#{$pattern}]); > > 729 } else { > > 730 $exp_cont = &{$pattern->[3]}($exp); > > 731 } > > My guess is thatthis is a malformed host name. It should be in the form. > > hostname.ext > > where ext is the top-level domain, such as .com, .net, .org, .etc. > > Joseph > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Fw: Net::SCP::Expect
Perhaps you should automate ssh logins by using a key that requires no passphrase, in other words so you can just "ssh [EMAIL PROTECTED]" and you're in with no interaction required. Then you don't need expect for that. Also, have you tried using the hostname IP address, just to see what happens? -tristram -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Fw: Net::SCP::Expect
I have tried IP address as well and get the same error message. I have considered alternate ways of doing this, but now I'm bent on figuring out why this isn't working for me! Thanks for the input. Jose - Original Message - From: "TN" <[EMAIL PROTECTED]> To: "'Jose Malacara'" <[EMAIL PROTECTED]>; "'R. Joseph Newton'" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Wednesday, October 01, 2003 9:59 AM Subject: RE: Fw: Net::SCP::Expect > Perhaps you should automate ssh logins by using a key that requires no > passphrase, in other words so you can just "ssh [EMAIL PROTECTED]" and > you're in with no interaction required. Then you don't need expect for > that. > Also, have you tried using the hostname IP address, just to see what > happens? > > -tristram > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Net -> SCP - errstr uninitialized
On Jan 5, 2004, at 10:49 AM, Paul Kraus wrote: Code #!/usr/bin/perl use strict; use warnings; &dhcpd; sub dhcpd { use Text::DHCPparse; use Net::SCP qw( scp iscp ); my $scp = Net::SCP -> new( 'hylafax', 'pkraus' ); $scp -> get ( 'dhcpd.leases' ) or die $scp->{errstr}; print "hello\n"; } Error - Use of uninitilazed value in die at C:\Documents and Settings\pdk\My Documents\perl code\squidlogs\squid.pl line12. Died at C:\... line 12 Ok, there are two things I would think about doing: a. check and see if you got the file dkcp.leases from the host hylafax - and of course a part of the problem there is whether or not that file would actually be where you think it is b. it is possible that a part of the problem is actually in how the local implementation of waitpid $pid, 0; if ( $? >> 8 ) { my $errstr = join('', <$error>); #chomp(my $errstr = <$error>); $self->{errstr} = $errstr; 0; } else { 1; } is working on your machine - the way you would like it to work - cf: <http://search.cpan.org/src/IVAN/Net-SCP-0.06/SCP.pm> check first the get() function and then into the scp() function. then play with say: $? = 12345; my $retval = funk_moi() ; #or die "errorno $?\n"; print "got back retval $retval\n"; $?= 3 ; $retval = funk_moi() ; #or die "errorno $?\n"; print "got back retval $retval\n"; # # sub funk_moi { if ( $? >> 8 ) { print "error case: $?\n"; 0; } else { print "is ok: $?\n"; 1; } } # end of funk_moi which generated for me: error case: 12345 got back retval 0 is ok: 3 got back retval 1 so there are a couple of places where things could be breaking down in strange and twisted manners. What did you see when you ran it in the perl debugger? ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
Re: Net -> SCP - errstr uninitialized
On Jan 5, 2004, at 12:32 PM, drieux wrote: On Jan 5, 2004, at 10:49 AM, Paul Kraus wrote: Code #!/usr/bin/perl use strict; use warnings; &dhcpd; sub dhcpd { use Text::DHCPparse; use Net::SCP qw( scp iscp ); my $scp = Net::SCP -> new( 'hylafax', 'pkraus' ); $scp -> get ( 'dhcpd.leases' ) or die $scp->{errstr}; print "hello\n"; } Error - Use of uninitilazed value in die at C:\Documents and Settings\pdk\My Documents\perl code\squidlogs\squid.pl line12. Died at C:\... line 12 waitpid $pid, 0; if ( $? >> 8 ) { my $errstr = join('', <$error>); #chomp(my $errstr = <$error>); $self->{errstr} = $errstr; 0; } else { 1; } WOW - did I miss a part of that: notice the problem of my $errstr = join('', <$error>); That is what I would be looking for as the oddity, since it would seem that the secquence there is what is "killing you". ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
Re: Net -> SCP - errstr uninitialized
Paul Kraus wrote: > Code > > #!/usr/bin/perl > > use strict; > use warnings; > > &dhcpd; > > sub dhcpd { > use Text::DHCPparse; > use Net::SCP qw( scp iscp ); > my $scp = Net::SCP -> new( 'hylafax', 'pkraus' ); Could it be that you are using or die one line too late? Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
Net::SCP is saving a file name with a wild card
Hi, I need to pull a file or files down every day that contain a specific string. Here's my code. #!/usr/bin/perl use strict; use Net::SCP; my $scp=' '; open (LOG, ">>/home/wesaysopost/logs/retrieve-wesayso-results.log") or die "Can't open logfile"; LOG-> autoflush(1); print LOG "Starting Retrieval Process"; $scp = Net::SCP->new ( "theserver.wesayso.com", "mylogin"); $scp->cwd("postingscript") or die "Can't change directories"; $scp->get ("acme_posting*") or die "Can't retrieve results"; close LOG; exit; The file I'm retrieving is acme_posting20110415.txt (date changes every day) The file is found, but it's being saved as acme_posting* I'm not specifying a local file name when I get the file, why is SCP saving it under a different name? Thanks in Advance! Dave
Re: Net::SCP is saving a file name with a wild card
On Apr 28, 9:31 am, dthack...@gmail.com (Dave Thacker) wrote: > Hi, > I need to pull a file or files down every day that contain a specific > string. Here's my code. > > #!/usr/bin/perl > use strict; > use Net::SCP; > > my $scp=' '; > open (LOG, ">>/home/wesaysopost/logs/retrieve-wesayso-results.log") or die > "Can't open logfile"; > LOG-> autoflush(1); > > print LOG "Starting Retrieval Process"; > $scp = Net::SCP->new ( "theserver.wesayso.com", "mylogin"); > $scp->cwd("postingscript") or die "Can't change directories"; > $scp->get ("acme_posting*") or die "Can't retrieve results"; > close LOG; > exit; > > The file I'm retrieving is acme_posting20110415.txt (date changes every > day) > > The file is found, but it's being saved as acme_posting* > > I'm not specifying a local file name when I get the file, why is SCP saving > it under a different name? Because perl doesn't know what the actual wildcarded transfer will return before the call returns. If fact, several files might be returned. How would perl know which one was the target... So, the basename of the remote file is used to generate the local file name. In this case basename('acme_posting*') just becomes the identical name "acme_posting*" Any reason you can't just specify an exact filename each day.. for instance: ($day, $mon, $yr ) = (localtime time())[3,4,5]; $file = sprintf( "acme_posting%d%02d%02d", $yr+1900, $mon, $day ); -- Charles DeRykus -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/