Re: not able to send a cookie to my ajax call:
thank you.I was able to resolve. It was the header data type issue. The AJAX call was expecting JSON output, and the script was sending text/html. I have now resolved this issue. I will update the question on website soon. thank you. Rajeev On Monday, June 13, 2016 4:51 AM, Shlomi Fish wrote: Hello Rajeev, your code exhibits many bad elements, and you don't seem to apply all the advice I've been giving you. Please go over http://perl-begin.org/tutorials/bad-elements/ , read it and internalise it. Furthermore, the E-mail headers of your message are obnoxious with a From: of the list and a reply-to to your personal Yahoo account. That may be a Yahoo mishap so please consider avoiding using Yahoo when posting to mailing lists. On Sun, 12 Jun 2016 21:23:49 +0000 (UTC) Rajeev Prasad via beginners wrote: > hello perl Gurus, > > I have put the same question on stack exchange, but getting no response... > I am NOT able to send the cookie in response to AJAX call to my webpage. > I am following it exactly as the manual says, putting the cookie in the > header of "$q", but it is not working :(the javascript code does not find any > cookie in document.cookie > Are you sure it should be in document.cookie rather than the AJAX's request cookie? Can you try listening on the wire using wireshark or whatever? Regards, Shlomi Fish > JSON response is being received and parsed just fine, below is simplified > version of the script: > > #!/usr/bin/perl > > use strict; > use warnings; > use JSON::XS; > use Template; > use CGI::Simple; > > my $q = new CGI::Simple; > > my $ajaxResp = {} ; #hashRef > my $ajaxResp_result; #success, fail, error > my $ajaxResp_mesg; #text mesg if needed > my $ajaxResp_obj; #file,json array etc. > my $ajaxResp_type = 'text'; #text/html/json/file/newPage etc... > > my $json = JSON::XS->new(); > > > my ($checkAuthAjaxResp_result,$uid,$sid,$cookie)=checkAuth($q); #external > function working fine. #good authentication at this point i have a well > formed cookie hash. $ajaxResp_result = 'success'; $ajaxResp_mesg = > 'successful login.'; $ajaxResp_type = 'text'; > $ajaxResp_obj = ''; > > > # returns a JSAON ARRAY of: status = error/success, data=mesg, responseType, > file=filename $ajaxResp->{'result'} = $ajaxResp_result; > $ajaxResp->{'responseType'} = $ajaxResp_type; > $ajaxResp->{'mesg'} = $ajaxResp_mesg; > $ajaxResp->{'obj'} = $ajaxResp_obj; > > my $response = $json->encode ($ajaxResp); # encode_json($ajaxResp); > > # set STDOUT to auto-flush and print header > $| = 1; > if ((defined $checkAuthAjaxResp_result) && ($checkAuthAjaxResp_result eq > 'pass')){ print $q->header(-type=>'application/json', > -cookie=>$cookie, > ); > }else { > print $q->header(-type=>'application/json', > ); > }print $response; > 1; > > > > ### I also tried but this does not work. I am > not seeing the cookie in the browser cookie table or on firebug log. # set > STDOUT to auto-flush and print header $| = 1; > if ((defined $checkAuthAjaxResp_result) && ($checkAuthAjaxResp_result eq > 'pass')){print $q->header(-cookie=>$cookie)} print "Content-type: > application/json\n\n"; print $response; > 1; > > > > ## earlier it was ending like this: and this works fine: > # set STDOUT to auto-flush and print header > $| = 1; > print "Content-type: application/json\n\n"; > print $response; > 1; > > > > another script which creates cookie as:my $cookie = $q->cookie( -name => > 'mySID', -value => $sid, > -expires => '+2m', > -path => '/cgi-bin/', > -domain => 'abc.com', > -secure => 1 > ); > > > > I am using TLS1.2 (SSL) for access. > > > > > pl also refer to: perl how to send cookie and json output via ajax response > > | > | > | > | | | > > | > > | > | > | | > perl how to send cookie and json output via ajax response > after a successful login/auth. my backend perl script has to send the > generated cookie and a json response hash ... | | > > | > > | > > > > > -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
not able to send a cookie to my ajax call:
hello perl Gurus, I have put the same question on stack exchange, but getting no response... I am NOT able to send the cookie in response to AJAX call to my webpage. I am following it exactly as the manual says, putting the cookie in the header of "$q", but it is not working :(the javascript code does not find any cookie in document.cookie JSON response is being received and parsed just fine, below is simplified version of the script: #!/usr/bin/perl use strict; use warnings; use JSON::XS; use Template; use CGI::Simple; my $q = new CGI::Simple; my $ajaxResp = {} ; #hashRef my $ajaxResp_result; #success, fail, error my $ajaxResp_mesg; #text mesg if needed my $ajaxResp_obj; #file,json array etc. my $ajaxResp_type = 'text'; #text/html/json/file/newPage etc... my $json = JSON::XS->new(); my ($checkAuthAjaxResp_result,$uid,$sid,$cookie)=checkAuth($q); #external function working fine. #good authentication at this point i have a well formed cookie hash. $ajaxResp_result = 'success'; $ajaxResp_mesg = 'successful login.'; $ajaxResp_type = 'text'; $ajaxResp_obj = ''; # returns a JSAON ARRAY of: status = error/success, data=mesg, responseType, file=filename $ajaxResp->{'result'} = $ajaxResp_result; $ajaxResp->{'responseType'} = $ajaxResp_type; $ajaxResp->{'mesg'} = $ajaxResp_mesg; $ajaxResp->{'obj'} = $ajaxResp_obj; my $response = $json->encode ($ajaxResp); # encode_json($ajaxResp); # set STDOUT to auto-flush and print header $| = 1; if ((defined $checkAuthAjaxResp_result) && ($checkAuthAjaxResp_result eq 'pass')){ print $q->header(-type=>'application/json', -cookie=>$cookie, ); }else { print $q->header(-type=>'application/json', ); }print $response; 1; ### I also tried but this does not work. I am not seeing the cookie in the browser cookie table or on firebug log. # set STDOUT to auto-flush and print header $| = 1; if ((defined $checkAuthAjaxResp_result) && ($checkAuthAjaxResp_result eq 'pass')){print $q->header(-cookie=>$cookie)} print "Content-type: application/json\n\n"; print $response; 1; ## earlier it was ending like this: and this works fine: # set STDOUT to auto-flush and print header $| = 1; print "Content-type: application/json\n\n"; print $response; 1; another script which creates cookie as:my $cookie = $q->cookie( -name => 'mySID', -value => $sid, -expires => '+2m', -path => '/cgi-bin/', -domain => 'abc.com', -secure => 1 ); I am using TLS1.2 (SSL) for access. pl also refer to: perl how to send cookie and json output via ajax response | | | | || | | | | | perl how to send cookie and json output via ajax response after a successful login/auth. my backend perl script has to send the generated cookie and a json response hash ... | | | |
series of numbers to range notation
so i have this series of numbers: 349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396,425,426,427,428,429,430,431,432,433,434,435,436,437,438,439,440,441,442,443,444,445,446,447,448,449,450,451,452,453,454,455,456,457,458,459,460,461,462,463,464,465,466,467,468,469,470,471,472,473,474,475,476,477,478,479,480,481,482,483,484,485,486,487,488,489,490,491,492,493,494,495,496 there are two ranges in there: 349-396, 425-496 any hints as to how to write a perl code to represent the series of numbers as a range? thank you. Rajeev
remotely operate web page/website
i need to go to a website and input some data in a specific input field, and run the query which opens a new page, i need to download and save it as an html page on my unix box. there are several blockages i am not able to figure out. 1. authentication is happening via another website, auth attempt is redirected to another website, which authenticates and stores some cookies on local PC, and loads back the page which called auth-site. 2. website needs internet explorer to operate properly. 3. this then presents menu from which i choose my choice and then that opens a form. 4. website uses javascript to build menus etc. 5. i fill some fields in the form and run it. (ok button) 6. returns result link on same page. 7. clicking the link opens the details in new page in which i am interested. websites of interest: http://xyz.abc.com/xyz/ and few more sites within same domain=> abc.com authentication website: https://www.myauth.abc.com/login/?retURL=http%3A%2F%2Fxyz.abc.com%2Fxyz%2Faction.login pl advice out of sooo many modules which will help me best here? I want to learn and use just one module for my all such "webpage-scraping/handling" . thanks in advance. Rajeev
Re: formatting a list
thank you Shawn. this works nicely for me. From: Shawn H Corey To: beginners@perl.org Cc: Rajeev Prasad Sent: Saturday, September 28, 2013 8:49 AM Subject: Re: formatting a list On Fri, 27 Sep 2013 22:59:01 -0700 (PDT) Rajeev Prasad wrote: > i want them to look neat, something like this: where they look in > line. I do not know before hand how long each word would be > > abc124567 > xy4z___xtr4__sdf > PQRSDR_xcvf__scc234 > > how could i use the sprintf to obtain such an effect? Try: #!/usr/bin/env perl use strict; use warnings; # -- my @data = (); my @maxs = (); while( ){ chomp; my @fields = split m{ _+ }msx, $_; for my $i ( 0 .. $#fields ){ my $len = length( $fields[$i] ); if( ( $maxs[$i] || 0 ) < $len ){ $maxs[$i] = $len; } } push @data, \@fields; } for my $row ( @data ){ my @fields = @$row; my $last = pop @fields; for my $i ( 0 .. $#fields ){ my $len = length( $fields[$i] ); print $fields[$i], '_' x ( $maxs[$i] - $len + 1 ); } print $last, "\n"; } __DATA__ abc_12_4567 xy4z_xtr4_sdf PQRSDR_xcvf_scc234 -- Don't stop where the ink does. Shawn -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
formatting a list
hello, following is obtained by concatenating 3 values using an underscore to produce a list: abc_12_4567 xy4z_xtr4_sdf PQRSDR_xcvf_scc234 i want them to look neat, something like this: where they look in line. I do not know before hand how long each word would be abc124567 xy4z___xtr4__sdf PQRSDR_xcvf__scc234 how could i use the sprintf to obtain such an effect? ty.
setting expect buffer size when reading/writing to PIPE
how to set length of read buffer when expect object is a PIPE. my ($pty, $pid) = $ssh->open2pty($command); my $exp = Expect->init($pty); _now how can i set the buffer size on this object? when i print following from script, both of the following values are 0 $exp->match_max() $exp->max_accum()
Re: printing content of a pipe
i see, it changes 'destination' for the rest of the perl script, you mean. i have another question which i will submit in new thread. From: Shlomi Fish To: Rajeev Prasad Cc: perl list Sent: Friday, June 28, 2013 11:45 AM Subject: Re: printing content of a pipe On Fri, 28 Jun 2013 07:37:57 -0700 (PDT) Rajeev Prasad wrote: > Shlomi/Uri, > what do you mean by 'It's a good idea not to use "select" on filehandles like > that because it willaffect the default filehandle permanently.'? shlomif@lap:~$ cat Test.pl #!/usr/bin/perl use strict; use warnings; use autodie; open my $o, '>', 'myfile.txt'; select($o); print "Hello World!\n"; close($o); shlomif@lap:~$ perl Test.pl shlomif@lap:~$ cat myfile.txt Hello World! shlomif@lap:~$ As you can see, print no longer printed to STDOUT but instead printed to $o. For more information, see http://perldoc.perl.org/functions/select.html . Regards, Shlomi Fish > > I am using perl 5.14 That's not too bad. Regards, Shlomi Fish > ty. > > > -- - Shlomi Fish http://www.shlomifish.org/ First stop for Perl beginners - http://perl-begin.org/ Reality to be conquered, must be obeyed. You’d better obey Chuck Norris or he’ll conquer you. — http://www.shlomifish.org/humour/bits/facts/Chuck-Norris/ Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: printing content of a pipe
Shlomi/Uri, what do you mean by 'It's a good idea not to use "select" on filehandles like that because it willaffect the default filehandle permanently.'? I am using perl 5.14 ty. From: Shlomi Fish To: perl list Sent: Friday, June 28, 2013 4:48 AM Subject: Re: printing content of a pipe Hi Rajeev, see below for some comments on your code. On Thu, 27 Jun 2013 15:07:50 -0700 (PDT) Rajeev Prasad wrote: > in the below code I am not able to print anything except whatever is in the > $pty. I want to print LINE_START: in the beginning of each line of the > output, but it does not print that, it only prints what the output of the > exceuted command produced. why is that so? > > while(<$pty>) { > > print "LINE_START: $. $_"; > } > > > > I am suspecting it has something to do with select STDOUT; $| = 1;, but i > dont know what. > > complete code: > > #!/usr/bin/perl > use strict; > use warnings; The strict and warnings are a good idea. > use Net::OpenSSH; > use Expect; > > select STDOUT; $| = 1; > select STDERR; $| = 1; It's a good idea not to use "select" on filehandles like that because it will affect the default filehandle permanently. Instead do: use IO::Handle; STDOUT->autoflush(1); STDERR->autoflush(1); > > my $password = $ARGV[0]; > my $target = $ARGV[1]; > my $runas = $ARGV[2]; > my $cmd = $ARGV[3]; This uses positional indexes and is subject to error. See: http://perl-begin.org/tutorials/bad-elements/#subroutine-arguments (my own link). > my $timeout = 20; > my $debug = 0; > > my $ssh = Net::OpenSSH->new($target, > user => 'abcd', > password => $password, > master_opts => [-o => 'StrictHostKeyChecking=no', > -o => 'ConnectTimeout 60'] > ); The formatting here is inconsistent. > my $sshExitCode = $ssh->error; > if ($sshExitCode eq "0") { > my $ostype= $ssh->capture("uname -s");chomp($ostype); > my $sudo_path=$ssh->capture("which sudo");chomp($sudo_path); > my $su_path=$ssh->capture("which su"); chomp($su_path); 1. You've placed two statements on the same line three times. 2. You may wish to extract a subroutine or a closure for doing that: my $read_str = sub { my ($cmd) = @_; my $ret = $ssh->capture($cmd); chomp($ret); return $ret; }; Also see what Uri said. Regards, Shlomi Fish -- - Shlomi Fish http://www.shlomifish.org/ Chuck Norris/etc. Facts - http://www.shlomifish.org/humour/bits/facts/ Well, one thing I can tell you about parenthood is that such things can progress from figurative to literal, extremely quickly. — http://www.shlomifish.org/humour/Summerschool-at-the-NSA/ Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
printing content of a pipe
in the below code I am not able to print anything except whatever is in the $pty. I want to print LINE_START: in the beginning of each line of the output, but it does not print that, it only prints what the output of the exceuted command produced. why is that so? while(<$pty>) { print "LINE_START: $. $_"; } I am suspecting it has something to do with select STDOUT; $| = 1;, but i dont know what. complete code: #!/usr/bin/perl use strict; use warnings; use Net::OpenSSH; use Expect; select STDOUT; $| = 1; select STDERR; $| = 1; my $password = $ARGV[0]; my $target = $ARGV[1]; my $runas = $ARGV[2]; my $cmd = $ARGV[3]; my $timeout = 20; my $debug = 0; my $ssh = Net::OpenSSH->new($target, user => 'abcd', password => $password, master_opts => [-o => 'StrictHostKeyChecking=no', -o => 'ConnectTimeout 60'] ); my $sshExitCode = $ssh->error; if ($sshExitCode eq "0") { my $ostype= $ssh->capture("uname -s");chomp($ostype); my $sudo_path=$ssh->capture("which sudo");chomp($sudo_path); my $su_path=$ssh->capture("which su"); chomp($su_path); if($sudo_path=~m/no sudo/){ if ($ostype eq "Linux"){ $sudo_path="/usr/bin/sudo"; } else{ $sudo_path="/usr/local/bin/sudo"; } } my ($pty, $pid) = $ssh->open2pty("$sudo_path -k; $sudo_path $su_path - $runas -c \"$cmd\"") or die "open2pty failed: " . $ssh->error . "\n"; my $expect = Expect->init($pty); $expect->raw_pty(1); $expect->expect($timeout, ':') or die "expect failed\n"; $expect->send("$password\n"); $expect->expect($timeout, "\n") or die "bad password\n"; while(<$pty>) { print "$. $_"; } } else { exit $sshExitCode; }
Re: Perl and Web Development
in my opinion it is better to use CSS/HTML and javascript to handle frontend work and perl doing all the backend processing, only generating json data for frontend to parse and display. perl is very good and most things have not changed much: like handling time, text/numeric data, text/database files etc. therefore perl has not changed much. older documentation is still as 'new' - Original Message - From: Michael Rasmussen To: Robert Wohlfarth Cc: begginers perl.org Sent: Monday, June 3, 2013 5:48 PM Subject: Re: Perl and Web Development On Mon, Jun 03, 2013 at 05:30:54PM -0500, Robert Wohlfarth wrote: > On Mon, Jun 3, 2013 at 5:03 PM, Ivan Torres wrote: > > > I dont know a book but perl dancer its pretty easy and you can find lots > > of documentation or catalyst > > > > http://www.perldancer.org/documentation > > > > > > On Mon, Jun 3, 2013 at 4:52 PM, Rich Johnson wrote: > > > >> Can anyone recommend a good book to use for building a website using > >> Perl? Specifically, I'm looking to build a backend to a mobile app. > >> Everything I've been trying to search for seems dated (2005 and earlier). > >> > >> > I'll second Catalyst. Start simple, and it's pretty easy to learn. > > http://www.catalystframework.org/ And I'll second Dancer, simplier, quicker to learn, plenty powerful. -- Michael Rasmussen, Portland Oregon Be Appropriate && Follow Your Curiosity Other Adventures: http://www.jamhome.us/ or http://gplus.to/MichaelRpdx A special random fortune cookie fortune: If, as some people think, cycling is so dangerous; how did I get to be 78 after about half a million kilometres? ~ Harold Bridge -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Email::Sender::Simple how to set priority?
using outlook and these are working with same sendmail binary from shell script. From: Rob Dixon To: perl list Cc: Rajeev Prasad Sent: Friday, April 26, 2013 9:21 PM Subject: Re: Email::Sender::Simple how to set priority? On 27/04/2013 00:21, Rajeev Prasad wrote: > following is still coming out as normal priority email. > > > > use strict; > use warnings; > use Email::MIME; > use Email::Sender::Simple qw(sendmail); > > > my @mesg=qw(fox jumps over the); > > my $subject='IMP mesg'; > > my $message = Email::MIME->create( > header_str => [ > From => '', > To => '<'y...@abc.com>', > Subject => $subject, > ], > attributes => { > encoding => 'quoted-printable', > charset => 'ISO-8859-1', > 'X-Priority' => 1, > 'X-MSMail-Priority' => 'High', > }, > body_str => "@mesg", > ); > > sendmail($message); Which email client are you using? Priority is a non-standard email feature and it depends which headers the client looks at. You might also want to try Importance => 'High' HTH, Rob -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Email::Sender::Simple how to set priority?
following is still coming out as normal priority email. use strict; use warnings; use Email::MIME; use Email::Sender::Simple qw(sendmail); my @mesg=qw(fox jumps over the); my $subject='IMP mesg'; my $message = Email::MIME->create( header_str => [ From => '', To => '<'y...@abc.com>', Subject => $subject, ], attributes => { encoding => 'quoted-printable', charset => 'ISO-8859-1', 'X-Priority' => 1, 'X-MSMail-Priority' => 'High', }, body_str => "@mesg", ); sendmail($message);
Re: [BackupPC-users] BackupPC future development (was: Backuppc and windows)
Has anyone shared this thread on perl mailing list yet? since we are looking for a perl devloper, i thought i would put it on the perl list to see if we get any response. thx. Rajeev - Original Message - From: "backu...@kosowsky.org" To: Tyler J. Wagner Cc: "General list for user discussion, questions and support" Sent: Saturday, April 6, 2013 9:56 PM Subject: Re: [BackupPC-users] BackupPC future development (was: Backuppc and windows) Tyler J. Wagner wrote at about 10:22:15 + on Monday, March 4, 2013: > On 2013-03-01 22:05, backu...@kosowsky.org wrote: > > Maybe it's time (or beyond time) to seek out Craig and see what his > > plans are for maintaining/evolving BackupPC are. If he is not > > reachable or is not interested in continuing, maybe we need to see if > > others are willing to take over leadership of this project... > > It's certainly beyond time for us to know what Craig is doing, or for him > to admit that v4 isn't going to happen as his closed room development. > > Is there an existing public version control? If not, I think it's time we > upload the current source to github and get started taking the bug fixes > in. To start with, there are a number of patches in the Debian releases > that can be accepted. > > Perl isn't my preferred environment, so I don't think I'm the right person > to do this. Jeffrey, it seems to me that you are. Are you interested? I doubt that I would be a very good maintainer... I just do computer stuff as a hobby and make no claims to any professional training or experience... but I would certainly be happy to help if there were a group interested in officially taking this over... -- Minimize network downtime and maximize team effectiveness. Reduce network management and security costs.Learn how to hire the most talented Cisco Certified professionals. Visit the Employer Resources Portal http://www.cisco.com/web/learning/employer_resources/index.html ___ BackupPC-users mailing list backuppc-us...@lists.sourceforge.net List: https://lists.sourceforge.net/lists/listinfo/backuppc-users Wiki: http://backuppc.wiki.sourceforge.net Project: http://backuppc.sourceforge.net/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Email::Mime not able to send array in mesg body
thx. I did achieve it by using join... join('',@array) From: David Precious To: beginners@perl.org Sent: Wednesday, February 20, 2013 1:01 PM Subject: Re: Email::Mime not able to send array in mesg body On Wed, 20 Feb 2013 10:41:51 -0800 (PST) Rajeev Prasad wrote: > hello follwoing code is sending empty email body. I am trying to send > HTML content in body of mesg. It works if I use a string instead of > array So, er, use a string? Why are you trying to pass an array as the body? What are you expecting to happen? The argument name even ends in _str - there's a clue there as to what it's expecting, no? You can use join() to turn all the elements of the array into a string - e.g. body_str => join "\n", @array, ... that would give you all the elements in @array, with a newline after each. If, however, you're trying to send a multi-part message, and the array contains the multiple parts, you want the 'parts' param, not 'body_str'. -- David Precious ("bigpresh") http://www.preshweb.co.uk/ www.preshweb.co.uk/twitter www.preshweb.co.uk/linkedin www.preshweb.co.uk/facebook www.preshweb.co.uk/cpan www.preshweb.co.uk/github -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Email::Mime not able to send array in mesg body
hello follwoing code is sending empty email body. I am trying to send HTML content in body of mesg. It works if I use a string instead of array. I tried sending reference to @email_body, but It simply printed array_ref in body. modules used are: use Email::MIME; use Email::Sender::Simple qw(sendmail); open(my $tmp_fh,"<",html_file) or die "error: $!"; @email_body = <$tmp_fh>; close $tmp_fh; my $message = Email::MIME->create( header_str => [ From => '', To => '', Subject => "Please see my test email", ], attributes => { encoding => 'quoted-printable', charset => 'ISO-8859-1', content_type => 'text/html' }, body_str => @email_body, ); sendmail($message);
Re: ok how about this: source code compressor
hmm i thought, it would load the whole script in memory and then execute. so a smaller file size will take less RAM... thx. From: Brian Fraser To: Rajeev Prasad Cc: perl list Sent: Friday, February 15, 2013 7:56 PM Subject: Re: ok how about this: source code compressor On Fri, Feb 15, 2013 at 8:19 PM, Rajeev Prasad wrote: > it not only decreases the size, to load in RAM, also make it 'little harder' > for cocky-novices to steal the tricks (perl guru's anyway dont care). > > > http://www.stunnix.com/prod/po/ (binary not present to download??) > http://blueboxtech.co.uk/perlplexity/ (failed to remove trailing comments...) > http://creativyst.com/cgi-bin/Prod/19/eg/PerlPack.pl Actually, it would probably use more RAM when compressed, so if that's your aim, this is the most counterproductive approach*; and in any case, the resulting optree would be of the same size regardless of the original code size. More importantly, no matter what solution you intend to use, if the code ultimately needs to be fed to perl, it doesn't stop anyone from calling it with -O=Deparse and getting a sane version; or if they have the "compressed" source, from just running it through perltidy. Trying to hide the source is a pointless, losing battle. That being said, you could try using B::C or PAR/FatPacker (I forget which) to distribute a binary of your program, which I imagine would be harder to read into. * perl reads the source line-by-line, only grabbing several lines at once when it needs to, like in multiline expressions or heredocs. A compressed program would put even more characters in a single line, forcing perl to use a bigger buffer, thus more RAM.
ok how about this: source code compressor
it not only decreases the size, to load in RAM, also make it 'little harder' for cocky-novices to steal the tricks (perl guru's anyway dont care). http://www.stunnix.com/prod/po/ (binary not present to download??) http://blueboxtech.co.uk/perlplexity/ (failed to remove trailing comments...) http://creativyst.com/cgi-bin/Prod/19/eg/PerlPack.pl
Re: obfuscating code
From: Paul Johnson To: John SJ Anderson Cc: beginners@perl.org Sent: Wednesday, February 13, 2013 5:50 PM Subject: Re: obfuscating code On Tue, Feb 12, 2013 at 03:18:51PM -0800, John SJ Anderson wrote: > > On Feb 12, 2013, at 3:05 PM, Kevin Walzer wrote: > > > Does Perl have the equivalent of Python bytecode files, i.e. pyc, > > that are obfuscated? If not, the OP's options may be limited. > > No such critter in Perl. Whilst that's true to a first, second and maybe even a third approximation, it's perhaps not absolutely correct: $ echo 'sub X { print 42 } 1' > X.pm $ perl5.8.9 -MX -eX 42 $ perl5.8.9 -MO=Bytecode,-H -MX -e1 > XX.pmc -e syntax OK $ perl5.8.9 -MXX -eX 42 $ od -x XX.pmc 000 2123 2f20 7375 2f72 6f6c 6163 2f6c 6b70 020 2f67 6570 6c72 642f 6665 7561 746c 702f 040 7265 2d6c 2e35 2e38 2f39 6962 2f6e 6570 060 6c72 2e35 2e38 0a39 7375 2065 7942 6574 100 6f4c 6461 7265 3020 302e 3b36 500a 424c 120 7843 3638 365f 2d34 696c 756e 0078 2e30 140 3630 0800 0800 0c00 5938 0161 160 6400 650d 0c40 5760 6d50 ... 0001440 0939 3b00 0010 7e3a 0003 8900 0001460 000e 0001465 But, be that as it may, even this won't stop someone who knows what they are doing being able to recover your source code, after a fashion. In practice, it's all about degree. Given that someone can run your code locally, and that if they have sufficient time and skill they will be able to reverse engineer your code to a greater or lesser extent (which is true for all programs in all languages), often you just want to hide your code from a curious observer, or to make it not worth someone's while to put in that effort. Modules such as Acme::Bleach have already been mentioned. One approach I have taken in the past is to embed perl inside a C program. I have encrypted the Perl source and added that as data in the C program. The C program decrypts the source and calls the embedded perl to execute it. You also need to do something clever so that "use" and friends look at the text in the C program first. Then you distribute the executable. That's probably more than sufficient for most purposes. It's probably also more than sufficient for this list. -- Paul Johnson - p...@pjcj.net http://www.pjcj.net thx. an obfuscation level 5 on a scale of 1 to 10 will be ok. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: obfuscating code
sorry, idea is dropped. From: Rajeev Prasad To: perl list Sent: Tuesday, February 12, 2013 11:01 AM Subject: obfuscating code freinds, what is the advice just for obfuscating code? platform is solaris. ty.
obfuscating code
freinds, what is the advice just for obfuscating code? platform is solaris. ty.
confusion about modules for email
Hello, I want to use an email module on my webserver, which is NOT running any mail server. I am not sure if I have install and configure a mail server first??? how does following modules work? they need a mail server running in the back? Mail::Sendmail Email::Sender pl advice from your experience. ty. Rajeev
expect module $expect->log_file(\&captureexpectout $arg2 $arg3);
Hello, I have a working sub like this: sub captureexpectout { my $data_coming_in_from_expect_call = shift; ...do something with data.. ... ... } which i am calling like this: $expect->log_file(\&captureexpectout); Now I want to call this subroutine with arguments. I tried below but I got error... $expect->log_file(\&captureexpectout($_,$myarg)); I was assuming that the data from expect call is contained in $_ but i get nothing. (seems like it passes blank to subroutine...) pl advice. Rajeev
Re: Net::Openssh disable password based login
nevermind. i figured it need to give this option: -o => 'PasswordAuthentication=no', ____ From: Rajeev Prasad To: perl list Sent: Sunday, January 27, 2013 1:10 PM Subject: Re: Net::Openssh disable password based login forgot to mention that, i have no control over ssh server (to add 'PasswordAuthentication no' option to server config) ________ From: Rajeev Prasad To: perl list Sent: Sunday, January 27, 2013 1:09 PM Subject: Net::Openssh disable password based login I guess this is openssh question. but, while using this module, and using key based authentication. some hosts which do not have key installed (perhaps user account does not yet exist there), throws password challenge and then the ssh program wait for too long, till the process is killed by hand (I dont know but the option 'ConnectTimeout 30' does not seem to have any impact). so how can i make this an strictly key based login? so that if key based login fails it does not try any further. pl advice. ty. Rajeev
Re: Net::Openssh disable password based login
forgot to mention that, i have no control over ssh server (to add 'PasswordAuthentication no' option to server config) ____ From: Rajeev Prasad To: perl list Sent: Sunday, January 27, 2013 1:09 PM Subject: Net::Openssh disable password based login I guess this is openssh question. but, while using this module, and using key based authentication. some hosts which do not have key installed (perhaps user account does not yet exist there), throws password challenge and then the ssh program wait for too long, till the process is killed by hand (I dont know but the option 'ConnectTimeout 30' does not seem to have any impact). so how can i make this an strictly key based login? so that if key based login fails it does not try any further. pl advice. ty. Rajeev
Net::Openssh disable password based login
I guess this is openssh question. but, while using this module, and using key based authentication. some hosts which do not have key installed (perhaps user account does not yet exist there), throws password challenge and then the ssh program wait for too long, till the process is killed by hand (I dont know but the option 'ConnectTimeout 30' does not seem to have any impact). so how can i make this an strictly key based login? so that if key based login fails it does not try any further. pl advice. ty. Rajeev
need suggestion stat vs Devl::Size for checking size very very frequently
i have a lot of data coming/pouring in from this: my ($rout, $pid) = $ssh->pipe_out($cmd); while (my $line = <$rout>) { print filehandle $line; } I want to stop writing after certain size is written (say 1gb). so i can try this: (it is working). But I am worried I am doing too many stat (and i am imagining it would be very expensive operation). there are about 500,000 lines coming in for 500mb data file, so below is doing stat 500 thousand times!!! my ($rout, $pid) = $ssh->pipe_out($cmd); while (my $line = <$rout>) { my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)= stat(filehandle); if ($size < $huge_limit ){ print $tmp_fh $line; } else { seek($tmp_fh, 0, 0); print $tmp_fh "file size limit reached\n"; kill TERM => $pid; last; } } ###end while so i am 'thinking' to try this: storing output in local temp array and checking when it reaches 10mb ($huge_limit) then save it to file and increase counter, when it happens total of $huge_limit_counter times (50 for 500mb limit). I close the channel and proceed. Here I am thinking, checking size of array 500,000 times (a 500k line array) is somehow 'more efficient' then checking file-size using stat. my $counter=1;my @tmp_arr; my ($rout, $pid) = $ssh->pipe_out($cmd); while (my $line = <$rout>) { push(@tmp_arr,$line); if (size(\@tmp_arr) > $huge_limit){ $counter++; if ($counter >= $huge_limit_counter){ kill TERM => $pid; last; } else { print $tmp_fh @tmp_arr; undef(@tmp_arr); } } } if(tell($rout) != -1){close $rout;} Please advice any suggestion for increasing efficiency of this code. thank you. Rajeev
how to break out of Net::OpenSSH $ssh->pipe_out($cmd); call
I am running a command on remote host to grab some data, i want to stop at a certain size. the following seem to be working (file size does not grow beyond 1MB on disk), but the process keeps running till i guess everything coming from that 'pipe' is finished. how can i stop/break/close the pipe as soon as i reach the limit? my $ssh = Net::OpenSSH->new($host); ... my ($rout, $pid) = $ssh->pipe_out($cmd); while (my $line = <$rout>) { my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)= stat($tmp_fh); if ($size < $huge_limit ){ print $tmp_fh $line; } else { print $tmp_fh "reached File Size limit."; last; } } this just simply times out. does not print any error message in the opened file. does stat operation affect the pointer inside the file? ty.
Re: Net::Openssh not fetching data
thx a lot Slava, it works! lastly, does the pipe_out does not 'store' data in RAM - and streams straight to disk? like collecting response from 'capture' in an array? rgds, Rajeev From: Salvador Fandino To: Rajeev Prasad Cc: perl list Sent: Monday, December 17, 2012 11:15 AM Subject: Re: Net::Openssh not fetching data On 12/17/2012 05:21 PM, Rajeev Prasad wrote: > > the following is _i think_ timing out. when it is run from within my script > > > ( @cmdresult, $cmderr ) = $ssh->capture($CMD); > > > where $CMD is: egrep "data_to_grep" *.data_file.txt > > the output is about 300Mb of data. > > further, the command when run on the remote system directly (after logging > in), takes only about 30 seconds. > > also, when we run from my localhost (bash shell) ssh "$CMD" > local.file.save > it completes within 2 minutes... > > please advice. > > ty. > Rajeev > 300MB of data may be too much for capturing and unless you are very carefully you will end with an script requiring several GBs of memory to run. Try saving the output to a file and process it afterwards line by line, or use Net::OpenSSH pipe_in method to read and process the data on the fly without storing it all in memory at once.
Net::Openssh not fetching data
the following is _i think_ timing out. when it is run from within my script ( @cmdresult, $cmderr ) = $ssh->capture($CMD); where $CMD is: egrep "data_to_grep" *.data_file.txt the output is about 300Mb of data. further, the command when run on the remote system directly (after logging in), takes only about 30 seconds. also, when we run from my localhost (bash shell) ssh "$CMD" > local.file.save it completes within 2 minutes... please advice. ty. Rajeev
Re: tt hash values not printing....
friends, i have resolved this now. I changed the way i was building the hash value: and then it worked fine. $my_hash->{$index} = [$val1, $val2]; - Original Message - From: Rajeev Prasad To: perl list Cc: Sent: Tuesday, October 30, 2012 6:17 PM Subject: tt hash values not printing Hello, Since I did not get any reply in last few hours. I am now posting this question to the perl list too. I apologize if you mind. thank you. starting with a hash ref my $my_hash = {}; building the hash in a loop... push(@tmp_arr,$val1); push(@tmp_arr,$val2); $my_hash->{$index} = \@tmp_arr; the elements for any key can be access fine as $my_hash->{$index}[0] I am passing a hash like this: my $vars = { myhash => $my_hash }; PROBLEM: trying to print like this, it prints the index correctly but does not print any values i am confused why? [%- FOREACH index IN myhash.keys.nsort -%] index number=[%index%] dt-time=[%myhash.$index.0%] detail=[%myhash.$index.1%] [% END -%] ___ templates mailing list templa...@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
tt hash values not printing....
Hello, Since I did not get any reply in last few hours. I am now posting this question to the perl list too. I apologize if you mind. thank you. starting with a hash ref my $my_hash = {}; building the hash in a loop... push(@tmp_arr,$val1); push(@tmp_arr,$val2); $my_hash->{$index} = \@tmp_arr; the elements for any key can be access fine as $my_hash->{$index}[0] I am passing a hash like this: my $vars = { myhash => $my_hash }; PROBLEM: trying to print like this, it prints the index correctly but does not print any values i am confused why? [%- FOREACH index IN myhash.keys.nsort -%] index number=[%index%] dt-time=[%myhash.$index.0%] detail=[%myhash.$index.1%] [% END -%] ___ templates mailing list templa...@template-toolkit.org http://mail.template-toolkit.org/mailman/listinfo/templates -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: simplestic perl module
Hello Shlomi, thx for the help. I tried and it worked. however I have few confusions. I tried it two ways (one yours and one from another website) I am not sure what is different between the two approaches. I do not know can you explain pl? from: http://www.tutorialspoint.com/perl/perl_modules.htm file: Mymodule.pm #!/usr/bin/perl package Mymodule; use strict; use warnings; require Exporter; our @ISA = qw(Exporter); # IT WAS FAILING WITH my our @EXPORT = qw(myroutine); ... sub myroutine{ ... } file: perlscript.pl #!/usr/bin/perl use strict; use warnings; use Template; use Mymodule; my ($output)=myroutine($input); then used your method: and it worked, as expected. I am not sure what is the diff between two approaches? can you pl help explain? ty. file: Mymodule.pm #!/usr/bin/perl package Mymodule; use strict; use warnings; use parent 'Exporter'; our @EXPORT_OK = qw(myroutine); file: perlscript.pl #!/usr/bin/perl use strict; use warnings; use Template; use Mymodule qw(myroutine); my ($output)=myroutine($input); - Original Message - From: Shlomi Fish To: Rajeev Prasad Cc: perl list Sent: Tuesday, October 9, 2012 11:33 AM Subject: Re: simplestic perl module Hi Rajeev, On Tue, 9 Oct 2012 08:54:31 -0700 (PDT) Rajeev Prasad wrote: > I want to execute this routine which is to be supplied two(sometimes > three) string variables. and will return two string variables. I want > to keep this routine in a separate file. how to do it? > > > > something like: > > ($var1,$var2) = routine > > I am either looking to keep this routine in a file which has many > routines. OR to keep this routine in a separate file, which has ONLY > this routine. > > please suggest how to pass variables and accept the multiple values > returned by the routine. > Please see: * http://perl-begin.org/topics/modules-and-packages/ for comprehensive info and tutorials about modules in Perl. As a teaser, what you can do for example is: [CODE] # This is file MyModule.pm package MyModule; use strict; use warnings; use parent 'Exporter'; our @EXPORT_OK = qw(my_function); sub my_function { my ($first_s, $second_s) = @_; # Silly expressions: my $first_ret = $first_s . $second_s . "Hello"; my $second_ret = $second_s . "Lambda" . $first_s; return ($first_ret, $second_ret); } 1; [/CODE] And then do: [CODE] #!/usr/bin/perl use strict; use warnings; use MyModule qw(my_function); # Use my_function() [/CODE] But you really should learn about modules in Perl. Regards, Shlomi Fish > ty. -- - Shlomi Fish http://www.shlomifish.org/ Interview with Ben Collins-Sussman - http://shlom.in/sussman Knuth is not God! God has already released TeX version 4.0. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Parallel::ForkManager and Net::OpenSSH to handle timeout
I am using Parallel::ForkManager to run multiple ssh sessions on various remote hosts. It is working fine. Sometimes I have a problem: problem is in Net::OpenSSH module that, for whatever reason, when far end does not respond the module does not close the SSH connection (i.e. timeout is not working). and, i am running ssh sessions inside forkmanager forked sessions. so i am wondering if there is anything I can use from forkmanager to terminate a child session based on some timeout value? I read Parallel::ForkManager documentation, but to me it looks like i can not. is there anyone more experienced on this, who can help? basic logic: foreach $host (@hostlist) { my $pm->start($host) and next; my $ssh = Net::OpenSSH->new($host, master_opts => [-o => 'StrictHostKeyChecking=no', -o => 'ConnectTimeout 30'], ); ...then some useful work thru ssh ... undef $ssh; $pm->finish; } ty. Rajeev
simplestic perl module
I want to execute this routine which is to be supplied two(sometimes three) string variables. and will return two string variables. I want to keep this routine in a separate file. how to do it? something like: ($var1,$var2) = routine I am either looking to keep this routine in a file which has many routines. OR to keep this routine in a separate file, which has ONLY this routine. please suggest how to pass variables and accept the multiple values returned by the routine. ty.
Re: expect.pm not recognising match string
ultimately salva's code at loc: http://cpansearch.perl.org/src/SALVA/Net-OpenSSH-0.58_04/sample/expect.pl is working. I will try to experiment more with it. From: Rajeev Prasad To: Salvador Fandino Cc: David Precious ; perl list Sent: Friday, September 28, 2012 6:05 PM Subject: Re: expect.pm not recognising match string Hello Salva, I tried many ways this is not happening. can you help? ( I did not try the there is nothing printed in results. single word commands like ls pwd are also not producing anything. since CU sudo does not allow more than 1 option at a time, i supply -k before supplying the command. please note that this sudo version does not have -S switch to pass password using stdin. so it expects password from terminal. can u pl help more. thx. $ssh->system("$sudo_path -k"); my @output = $ssh->capture({tty => 1, stdin_data => "$PASS"}, $sudo_path, "-p",'', "$cmd"); print " result=@output \n"; OR $ssh->system("$sudo_path -k"); my @output = $ssh->capture({stdin_data => "$PASS"}, $sudo_path, "-p",'', "$cmd"); print " result=@output \n"; From: Salvador Fandino To: Rajeev Prasad Cc: David Precious ; perl list Sent: Friday, September 7, 2012 2:10 AM Subject: Re: expect.pm not recognising match string On 09/07/2012 12:54 AM, Rajeev Prasad wrote: > no because first i have to sudo to some other ID and then run commands. You should be able to call every command through 'sudo', something like this: $ssh->capture('sudo', @sudo_opts, @cmd1); $ssh->capture('sudo', @sudo_opts, @cmd2); There are several versions of sudo with different capabilities and besides that, its configuration also varies widely between operating systems and distributions. So you may have to experiment a lot in order to find the right set of arguments that gets it to work. Some things that may help: Asking Net::OpenSSH to allocate a tty for the channel: $ssh->capture({ tty => 1, ... }, 'sudo', ...); You should be able to pass the password through stdin without using Expect: $ssh->capture({ stdin_data => "$password\n", ...}, ...); And read the sudo documentation for the specific version used on the target hosts. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
sudo module; how to use on remote system
Hello Joe, How to use your module on a remote system? module is not installed on remote system, but on my local machine. i am usinf net::openssh to connect to remote system. tx. Rajeev
Re: expect.pm not recognising match string
Hello Salva, I tried many ways this is not happening. can you help? ( I did not try the there is nothing printed in results. single word commands like ls pwd are also not producing anything. since CU sudo does not allow more than 1 option at a time, i supply -k before supplying the command. please note that this sudo version does not have -S switch to pass password using stdin. so it expects password from terminal. can u pl help more. thx. $ssh->system("$sudo_path -k"); my @output = $ssh->capture({tty => 1, stdin_data => "$PASS"}, $sudo_path, "-p",'', "$cmd"); print " result=@output \n"; OR $ssh->system("$sudo_path -k"); my @output = $ssh->capture({stdin_data => "$PASS"}, $sudo_path, "-p",'', "$cmd"); print " result=@output \n"; From: Salvador Fandino To: Rajeev Prasad Cc: David Precious ; perl list Sent: Friday, September 7, 2012 2:10 AM Subject: Re: expect.pm not recognising match string On 09/07/2012 12:54 AM, Rajeev Prasad wrote: > no because first i have to sudo to some other ID and then run commands. You should be able to call every command through 'sudo', something like this: $ssh->capture('sudo', @sudo_opts, @cmd1); $ssh->capture('sudo', @sudo_opts, @cmd2); There are several versions of sudo with different capabilities and besides that, its configuration also varies widely between operating systems and distributions. So you may have to experiment a lot in order to find the right set of arguments that gets it to work. Some things that may help: Asking Net::OpenSSH to allocate a tty for the channel: $ssh->capture({ tty => 1, ... }, 'sudo', ...); You should be able to pass the password through stdin without using Expect: $ssh->capture({ stdin_data => "$password\n", ...}, ...); And read the sudo documentation for the specific version used on the target hosts. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: expect.pm not recognising match string
no because first i have to sudo to some other ID and then run commands. From: David Precious To: Rajeev Prasad Cc: perl list Sent: Thursday, September 6, 2012 4:57 AM Subject: Re: expect.pm not recognising match string On Wed, 5 Sep 2012 11:27:28 -0700 (PDT) Rajeev Prasad wrote: > inside ssh tunnel (using Net::Openssh), a pty is opened. > > then an exp object is init to this pty my $exp=Expect->init($pty); > > > using this object i am trying to run about quite a few commands on > remote system. [...] > I would like to send the command and then wait fo rit to finish > (lookout for system prompt) and then execute next command in loop. Is there a reason you can't just let Net::OpenSSH do this for you? From its docs, you can use the capture() / capture2() methods (depending on whether you need to capture just STDOUT or STDOUT and STDERR from the process). For example: for my $command (@commands) { my $result = $ssh->capture($command); } I believe that should work, no? -- David Precious ("bigpresh") http://www.preshweb.co.uk/ www.preshweb.co.uk/twitter www.preshweb.co.uk/linkedin www.preshweb.co.uk/facebook www.preshweb.co.uk/cpan www.preshweb.co.uk/github -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
expect.pm not recognising match string
inside ssh tunnel (using Net::Openssh), a pty is opened. then an exp object is init to this pty my $exp=Expect->init($pty); using this object i am trying to run about quite a few commands on remote system. I am using following method. It has two flaws: 1) does not work if $exp->expect(5); line is removed. (This is like a sleep). 2) only waits for 5 seconds, so command which run longer - do not finish before the next command is run. which is a problem (messes up output). useExpect; ... ... foreachmy$cmd (@cmd_array){ $exp->expect(3, [qr/($|#)/ => sub { shift->send("$cmd");}] ); $exp->expect(5); } I would like to send the command and then wait fo rit to finish (lookout for system prompt) and then execute next command in loop. I tried many things/ways, none work. Pl suggest. I posted question here: http://stackoverflow.com/questions/12272191/perl-expect-running-30-commands-remotely/12273286 unfortunately no help yet. thank you. Rajeev
moving from 32bit to 64bit linux perl support?
Hello friends, I have a lot of scripts written in perl on 32 bit ubuntu linux. i am thinking to migrate to newer 64bit linux server, it will come with perl package, but i am not sure whether there will be 64 bit modules available? lets say for example for Net::Telnet will there be a 64bit version available? lets say on ubuntu 64 bit server? similarly for other modules... pl advice. thank you. Rajeev
many people using same file
can multiple users run the same script, at same time, which opens couple of files (file handles) for "reading" only? I would assume yes, but I want to know for sure. thx in advance. Rajeev
Re: re-reading from already read file handle
Rob, yes you are right. I apologize if that is not liked. I will not do so in future. I will atleast wait a couple of hours, before i go to any other forum. your help is valuable to me. ty. Rajeev From: Rob Dixon To: Rajeev Prasad ; perl list Sent: Monday, August 20, 2012 6:15 PM Subject: Re: re-reading from already read file handle Rajeev Prasad wrote: >I opened a file to read from line by line. > > >open(FH,"<","$myfile") or die "could not open $myfile: $!"; >while () >{ >...do something > >} > >later on in program, try to re-read the file (walk thru the file >again): >while () >{ >...do something > >} > >and realized that it is as if the control within file is at the EOF and >will not iterate from first line in the file is this default >behaviour? how to work around this? file is big and I do not want to >keep in memory as array. so is my only option is to close and open the >file again? > >pl advice. >ty. >Rajeev This question is double-posted on Stack Overflow Rob -- This is sent from my phone. Please excuse the brevity.
Re: re-reading from already read file handle
Thx. I did some timestamp prints from within script, this piece is taking too long: almost 5 minutes to complete...!!! fyi, the strArr array contains about 1500 string elements. (this loop runs that many times) the file tmp_FH_SR is 27Mb and 300,000 lines of data. the file tmp_FH_RL is 13 Mb with around 150,000 lines of data. I have changed the names of variable to protect actual names... in the first while, based on the fact that the $str was found only once in the file, i obtain another field from the matching record. I use this field to search for no of occurances of this filed in another file. Based on that output i do further things with $str. my $tmp_srt; foreach my $str (@strArr) { my $tmp1; my $count=0; seek $tmp_FH_SR,0,0; while (<$tmp_FH_SR>) { my $line=$_;chomp($line); if ($line=~ m/\"$str\"/) { $count++; if ($count == 1) { my @tmp_line_ar = split(/\,/,$line); $tmp_str=$tmp_line_ar[10]; } } } if ($count == 1) { seek $tmp_FH_RL,0,0; while (<$tmp_FH_RL>) { my $line=$_;chomp($line); if ($line=~m/\"$tmp_str\"/) {$count++;} } if($count == 1){push(@another_str_arr,$str);} } } how can i make it faster? read the 27mb and 13mb files in an array one time and work? From: Jim Gibson To: perl list Sent: Monday, August 20, 2012 4:04 PM Subject: Re: re-reading from already read file handle On Aug 20, 2012, at 1:39 PM, Rajeev Prasad wrote: > thank you. seek did the job. > > by the way can this be made any better? > > just want to find out in how many records string was found: > > my $count=0; > seek $tmp_FH,0,0; > while (<$tmp_FH>) > { > my $line=$_;chomp($line); > if ($line=~m/\"$str\"/) {$count++;} #in the file $str >string would be in quotes > } Two possible efficiency improvements: 1. Since you are just searching each line for a string, you can skip the chomp($line). 2. Searching for a fixed string might be done faster by using the index() function rather than invoking the regular expression engine: $count++ if index($line,"\"$str\"") != -1; Neither of these modifications is likely to produce a significant speed-up. You should benchmark them to see what the difference actually is to see if it is worth it in your case. The speed bottleneck will still be reading the file from a physical device. If possible, you should combine searching for the string with whatever processing you are doing on the file during the first read, and only read the file once. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: re-reading from already read file handle
thank you. seek did the job. by the way can this be made any better? just want to find out in how many records string was found: my $count=0; seek $tmp_FH,0,0; while (<$tmp_FH>) { my $line=$_;chomp($line); if ($line=~m/\"$str\"/) {$count++;} #in the file $str string would be in quotes } From: Andy Bach To: Rajeev Prasad Cc: perl list Sent: Monday, August 20, 2012 2:10 PM Subject: Re: re-reading from already read file handle On Mon, Aug 20, 2012 at 2:00 PM, Rajeev Prasad wrote: > is this default behaviour? how to work around this? file is big and I do not > want to keep in memory as array. so is my only option is to close and open > the file again? Yes, that's the default. "seek" lets you reset things though perldoc -f seek seek FILEHANDLE,POSITION,WHENCE Sets FILEHANDLE’s position, just like the "fseek" call of "stdio". FILEHANDLE may be an expression whose value gives the name of the filehandle. The values for WHENCE are 0 to set the new position in bytes to POSITION, 1 to set it to the current position plus POSITION, and 2 to set it to EOF plus POSITION (typically negative). For WHENCE you may use the constants "SEEK_SET", "SEEK_CUR", and "SEEK_END" (start of the file, current position, end of the file) from the Fcntl module. Returns 1 upon success, 0 otherwise. -- a Andy Bach, afb...@gmail.com 608 658-1890 cell 608 261-5738 wk -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
re-reading from already read file handle
I opened a file to read from line by line. open(FH,"<","$myfile") or die "could not open $myfile: $!"; while () { ...do something } later on in program, try to re-read the file (walk thru the file again): while () { ...do something } and realized that it is as if the control within file is at the EOF and will not iterate from first line in the file is this default behaviour? how to work around this? file is big and I do not want to keep in memory as array. so is my only option is to close and open the file again? pl advice. ty. Rajeev
Re: subroutine in seperate file, question
Thank you. I am confused about how to send variables to this ext.pl and get values (scalars) back into main.pl another confusion is from web the cgi will run, i want to check cookies in external subroutine file and redirect to some website based on some condition, or gives some values back to calling program if condition is met. can i do this kind of thing by putting this subroutine in external file? i am reading "perldoc perlmod" but still not able to understand the concept From: Shawn H Corey To: beginners@perl.org Sent: Saturday, August 11, 2012 6:43 AM Subject: Re: subroutine in seperate file, question On Sat, 11 Aug 2012 02:49:56 -0400 shawn wilson wrote: > On Aug 10, 2012 11:41 PM, wrote: > > > > > I mean to ask, wether they will clash with the same loaded modules > loaded > > > in calling script? > > > > > > > No. they are loaded only once. > > > > Well, they will both be in ISA to look up separately but there is no > conflict. No, @ISA is used only by Exporter.pm It's %INC that records what modules have been loaded. See `perldoc perlvar` and search for /%INC/ -- Just my 0.0002 million dollars worth, Shawn Programming is as much about organization and communication as it is about coding. _Perl links_ official site : http://www.perl.org/ beginners' help : http://learn.perl.org/faq/beginners.html advance help : http://perlmonks.org/ documentation : http://perldoc.perl.org/ news : http://perlsphere.net/ repository : http://www.cpan.org/ blog : http://blogs.perl.org/ regional groups : http://www.pm.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: subroutine in seperate file, question
I mean to ask, wether they will clash with the same loaded modules loaded in calling script? From: "pa...@riseup.net" To: Rajeev Prasad Cc: perl list Sent: Friday, August 10, 2012 9:05 PM Subject: Re: subroutine in seperate file, question Yes, the modules in required file will be loaded. $ cat ext.pl use CGI; use DBI; 1; $ cat main.pl require 'ext.pl'; use Data::Dumper; print Dumper \%INC; Thus run perl main.pl to see what prints. > i want to keep a peice of code which uses CGI and DBIx module in a > seperate file, and want to include it in all my scripts as follows: > > require "/path/to/script/file"; > > I am not sure if the calling program is also using same modules CGI and > DBIx what kind of unknown errors i might get? anyone know?
subroutine in seperate file, question
i want to keep a peice of code which uses CGI and DBIx module in a seperate file, and want to include it in all my scripts as follows: require "/path/to/script/file"; I am not sure if the calling program is also using same modules CGI and DBIx what kind of unknown errors i might get? anyone know? ty. Rajeev
DBIx schema loader (dump schema using make_schema_at) wierd behaviour
Hello, am I missing anything? when I dump schema of my database using schema loader's make_schema_at. Some .pm file names under Result corrosponding to folders have names chnaged! they do not match to table names!! e.g. table name costlycookies shows up as Costlycooky.pm !!! another table cheapcookis show up as Cheapcooky.pm another table named els is showing up a El.pm !!! when i cat these files the table names and other details are all good. But due to this 'wrong' .pm file naming I am getting this error in my code: DBIx::Class::Schema::resultset(): Can't find source for Costlycookies at /my/path/cgi-bin/myscript.pl line 53 line 53 in my code:... $coki_rs = $schema->resultset('Costlycookies')->search( why is this happening? before this fresh dumping operation, I changed the indexed key from general indexed key to primary index key on almost all tables, but the old table's *.pm file names still look good. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: how to set session variable (not session cookie) using perl CGI
Thank you Ron and David. - Original Message - From: Ron Bergin To: Rajeev Prasad Cc: perl list Sent: Tuesday, August 7, 2012 9:36 PM Subject: Re: how to set session variable (not session cookie) using perl CGI -- Rajeev Prasad wrote: > I am using CGI.pm on my website, but I generate my pages using TT > (template Toolkit). > > I have few questions: > > 0. how to have a session variable (not a session cookie)? If I do not want > to use cookie, do i have to store session data in a temp file on server > and check it with each page load? > > > 1. How do I pass a cookie to the page I am displaying using tt ? is > following ok? > > print "Content-type: text/html\n\n"; > print $q->header(-cookie=>$mycookie); > ...further code to generate page using tt > > 2. another related issue is: How do I send a redirect URL to the browser > client, based on some conditions in the logic? > > ty. > Rajeev > > -- http://search.cpan.org/~markstos/CGI-Session-4.48/lib/CGI/Session.pm --- Ron Bergin -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
how to set session variable (not session cookie) using perl CGI
I am using CGI.pm on my website, but I generate my pages using TT (template Toolkit). I have few questions: 0. how to have a session variable (not a session cookie)? If I do not want to use cookie, do i have to store session data in a temp file on server and check it with each page load? 1. How do I pass a cookie to the page I am displaying using tt ? is following ok? print "Content-type: text/html\n\n"; print $q->header(-cookie=>$mycookie); ...further code to generate page using tt 2. another related issue is: How do I send a redirect URL to the browser client, based on some conditions in the logic? ty. Rajeev -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: net::openssh error in CGI: Invalid or bad combination of options ('key_path')
so finally I settle down for uid password authentication. plus i built the .ssh directory under /var/www (home folder for www-data). and use it as ctl_dir, i get no error message and it works. I am worried about below: 1. uid/pwd is not safe for scripts, so how can i use key based authentication? 2. since the module insist on having a .ssh folder in home directory(/var/www), of web user (www-data on linux), how safe is it to have a .ssh folder under /var/www ?? anyone know? ty. Rajeev - Original Message - From: Rajeev Prasad To: Shlomi Fish Cc: perl list Sent: Thursday, June 28, 2012 2:36 PM Subject: Re: net::openssh error in CGI: Invalid or bad combination of options ('key_path') - Original Message - From: Shlomi Fish To: Rajeev Prasad Cc: perl list Sent: Thursday, June 28, 2012 12:46 PM Subject: Re: net::openssh error in CGI: Invalid or bad combination of options ('key_path') Hi Rajeev, On Thu, 28 Jun 2012 10:00:08 -0700 (PDT) Rajeev Prasad wrote: > hello can anyone help? > > following is failing: > > my $ssh = Net::OpenSSH->new($host, > user => "abc123", > ctl_dir => "/home/openssh_lib_home", > key_path => "/home/openssh_lib_home/.ssh/", > master_opts => [-o => 'StrictHostKeyChecking=no', > -o => 'ConnectTimeout 60'], > ); key_path should point to the file of the private key on the disk - not its containing directory. Regards, Shlomi Fish > > getting error: Invalid or bad combination of options ('key_path') > > > folder permissions are: > > drwxrwsr-x 3 www-data www-data 4096 2012-06-28 16:24 /home/openssh_lib_home > > > drwxr-sr-x 2 www-data www-data 4096 2012-06-28 16:24 > /home/openssh_lib_home/.ssh > > -rw--- 1 www-data www-data 1679 2012-06-27 21:30 > /home/openssh_lib_home/.ssh/id_rsa > -rw-r--r-- 1 www-data www-data 395 2012-06-28 16:24 > /home/openssh_lib_home/.ssh/id_rsa.pub > -- - Shlomi Fish http://www.shlomifish.org/ My Favourite FOSS - http://www.shlomifish.org/open-source/favourite/ Every successful open source project will eventually spawn a sub‐project. Please reply to list if it's a mailing list post - http://shlom.in/reply . hello Shlomi, howdy I made the change, but it still gives same error. my $ssh = Net::OpenSSH->new($host, user => "abc123", ctl_dir => "/home/openssh_lib_home", key_path => "/home/openssh_lib_home/.ssh/id_rsa", master_opts => [-o => 'StrictHostKeyChecking=no', -o => 'ConnectTimeout 60'], ); It works with username password supplied. but i suspect some internal issue as i can see in error logs - when i run it with userid/passwd and ctl_dir options, it still tries to access/save ssh info in /var/www.ssh !!! that however does not stop the ssh from being happening. key_path options still dont work :( -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: net::openssh error in CGI: Invalid or bad combination of options ('key_path')
- Original Message - From: Shlomi Fish To: Rajeev Prasad Cc: perl list Sent: Thursday, June 28, 2012 12:46 PM Subject: Re: net::openssh error in CGI: Invalid or bad combination of options ('key_path') Hi Rajeev, On Thu, 28 Jun 2012 10:00:08 -0700 (PDT) Rajeev Prasad wrote: > hello can anyone help? > > following is failing: > > my $ssh = Net::OpenSSH->new($host, > user => "abc123", > ctl_dir => "/home/openssh_lib_home", > key_path => "/home/openssh_lib_home/.ssh/", > master_opts => [-o => 'StrictHostKeyChecking=no', > -o => 'ConnectTimeout 60'], > ); key_path should point to the file of the private key on the disk - not its containing directory. Regards, Shlomi Fish > > getting error: Invalid or bad combination of options ('key_path') > > > folder permissions are: > > drwxrwsr-x 3 www-data www-data 4096 2012-06-28 16:24 /home/openssh_lib_home > > > drwxr-sr-x 2 www-data www-data 4096 2012-06-28 16:24 > /home/openssh_lib_home/.ssh > > -rw--- 1 www-data www-data 1679 2012-06-27 21:30 > /home/openssh_lib_home/.ssh/id_rsa > -rw-r--r-- 1 www-data www-data 395 2012-06-28 16:24 > /home/openssh_lib_home/.ssh/id_rsa.pub > -- - Shlomi Fish http://www.shlomifish.org/ My Favourite FOSS - http://www.shlomifish.org/open-source/favourite/ Every successful open source project will eventually spawn a sub‐project. Please reply to list if it's a mailing list post - http://shlom.in/reply . hello Shlomi, howdy I made the change, but it still gives same error. my $ssh = Net::OpenSSH->new($host, user => "abc123", ctl_dir => "/home/openssh_lib_home", key_path => "/home/openssh_lib_home/.ssh/id_rsa", master_opts => [-o => 'StrictHostKeyChecking=no', -o => 'ConnectTimeout 60'], ); It works with username password supplied. but i suspect some internal issue as i can see in error logs - when i run it with userid/passwd and ctl_dir options, it still tries to access/save ssh info in /var/www.ssh !!! that however does not stop the ssh from being happening. key_path options still dont work :( -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
net::openssh error in CGI: Invalid or bad combination of options ('key_path')
hello can anyone help? following is failing: my $ssh = Net::OpenSSH->new($host, user => "abc123", ctl_dir => "/home/openssh_lib_home", key_path => "/home/openssh_lib_home/.ssh/", master_opts => [-o => 'StrictHostKeyChecking=no', -o => 'ConnectTimeout 60'], ); getting error: Invalid or bad combination of options ('key_path') folder permissions are: drwxrwsr-x 3 www-data www-data 4096 2012-06-28 16:24 /home/openssh_lib_home drwxr-sr-x 2 www-data www-data 4096 2012-06-28 16:24 /home/openssh_lib_home/.ssh -rw--- 1 www-data www-data 1679 2012-06-27 21:30 /home/openssh_lib_home/.ssh/id_rsa -rw-r--r-- 1 www-data www-data 395 2012-06-28 16:24 /home/openssh_lib_home/.ssh/id_rsa.pub -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Net::OpenSSH failing in CGI
i was able to resolve that with creating a folder for www-data under /home dont know how secure but thats what i could think of.. new problem is: Could not create directory '/var/www/.ssh'.\r Failed to add the host to the list of known hosts (/var/www/.ssh/known_hosts).\r Permission denied (gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive).\r well, why is it trying to create anything in /var/www, havent i already defined ctl_dir ??? and, when i try to use key_path option i get this error: (so i am not using it for now) Invalid or bad combination of options ('key_path') at . currently it looks like: my $ssh = Net::OpenSSH->new($host, user => "abc123", ctl_dir => "/home/openssh_lib_home/" master_opts => [-o => 'StrictHostKeyChecking=no', -o => 'ConnectTimeout 60'], ); # ls -l /home|grep open drwxrwsr-x 2 www-data www-data 4096 2012-06-27 21:54 openssh_lib_home - Original Message - From: Rajeev Prasad To: perl list Cc: Sent: Wednesday, June 27, 2012 4:13 PM Subject: Net::OpenSSH failing in CGI my $ssh = Net::OpenSSH->new($host, user => "abc123", ctl_dir => "/var/www/mysite.com/www/openssh_lib_home/" ); ssh is not happening, when i catch the error, i get below: error: ctl_dir /var/www/mysite.com/www/openssh_lib_home/ is not secure folder is : $ ls -l /var/www/mysite.com/www/|grep ssh drwx-- 2 abc123 abc123 4096 2012-06-27 20:41 openssh_lib_home I also changed ownership to www-data, but it still throws same error. drwxr-xr-x 2 www-data www-data 4096 2012-06-27 21:06 openssh_lib_home background: first it was trying to create under /var/www: was failing due to no permission. unable to create ctl_dir /var/www/.libnet-openssh-perl: No such file or directory so i added option ctl_dir, but i am not sure why is it failing now, to me permissions look ok??? is it still trying to start ssh as www-data (even if it is, then why wont it work if i make www-data as owner of folder)? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Net::OpenSSH failing in CGI
my $ssh = Net::OpenSSH->new($host, user => "abc123", ctl_dir => "/var/www/mysite.com/www/openssh_lib_home/" ); ssh is not happening, when i catch the error, i get below: error: ctl_dir /var/www/mysite.com/www/openssh_lib_home/ is not secure folder is : $ ls -l /var/www/mysite.com/www/|grep ssh drwx-- 2 abc123 abc123 4096 2012-06-27 20:41 openssh_lib_home I also changed ownership to www-data, but it still throws same error. drwxr-xr-x 2 www-data www-data 4096 2012-06-27 21:06 openssh_lib_home background: first it was trying to create under /var/www: was failing due to no permission. unable to create ctl_dir /var/www/.libnet-openssh-perl: No such file or directory so i added option ctl_dir, but i am not sure why is it failing now, to me permissions look ok??? is it still trying to start ssh as www-data (even if it is, then why wont it work if i make www-data as owner of folder)? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
file rows to colum using Text::CSV ?
i wrote this code which turns rows into columns from a csv file (here you see as 'in' array) I am finding it difficult to figure to do this using Text::CSV ??? can anyone suggest how to convert this to use Text::CSV ? thank you. Rajeev #!/usr/bin/perl use warnings; use strict; #array rows to column my @in = ("1,2,3,4,a,b,c\n","z,y,x,w,9,8,7\n","e,f,g,h,5,4,6\n"); my @out; my @tmp; for my $x (0 .. $#in) { chomp($in[$x]); my @x2=split(/,/,$in[$x]); for my $m (0 .. $#x2) { if ($x eq $#in) { $tmp[$m][$x]=$x2[$m]."\n"; } else { $tmp[$m][$x]=$x2[$m]; } } } for my $x (0 .. $#tmp) { push(@out,join(",",@{$tmp[$x]})); } print "out-ele= $#out out=\n@out";
how to appending to expect output ?
hello, i want to append a dynamic string stored in a variable to the beginning of each output row of the expect command, but do not know how to do it. can anyone help pl? module used is Expect I am using this statement before i run any command on remote host, it captures EVERYTHING. I want to pre-append each line with a string my ( $pty, $pid ) = $ssh->open2pty({stderr_to_stdout => 1}, '/usr/local/bin/sudo', -p => 'runasroot:', 'su', '-') my $expect = Expect->init($pty); $expect->log_file("$OUTPUTLOG"); $expect->expect(3, [ qr/runasroot:/ => sub { shift->send("$PASS\n");exp_continue;} ], [ qr/[Sorry|Permission]/ => sub { die "Login failed: check sudo path"; } ] ); foreach my $cmd (@cmds){ $expect->expect(3, [ qr/#/ => sub { shift->send("\n$cmd \n");exp_continue;}] ); $expect->expect(5); } i want to append an string to the beginning of each line of output from running the command, but i am not sure how to catch the output of each command before it goes into log file. ty Rajeev -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
bug in net::openssh? or what am i doing wrong?
http://cpan.uwinnipeg.ca/htdocs/Net-OpenSSH/Net/OpenSSH.html#scp_put following is failing with an error when $folder is not defined. is that correct? i think it should assume $folder as null variable and continue to save in home folder on destination??? $scpresult = $ssh->scp_put($file,$folder); I get this error: Use of uninitialized value $arg in string eq at /usr/local/share/perl/5.10.1/Net/OpenSSH.pm line 771, line 2. I can see when i check that $scpresult is undef. scp_get is working fine with exact similar syntax and undefined $folder.
Re: moving from ubuntu 10.04 to 12.04. how to have same PERL modules there?
thx Shawn, I guess, it would not check which modules have newer versions available, and will install the same modules whihc were there in old PC. I install only those modules which come thru ubuntu, so that (I assume) there is some compatibility testing already done. (anD) it does not break anythign else in my PERL install. I will try it on test system first. I found another simple way, which works for me (my scripts are simple ones): I would just go thru all my scripts and see what am I 'useing' like __ use abc::def __ and then make a list of those. then go on target system and open some tool like synaptic (for ubuntu) and install all those modules. :) I will try that too. ty. Rajeev From: Shawn H Corey To: beginners@perl.org Sent: Tuesday, June 5, 2012 3:29 PM Subject: Re: moving from ubuntu 10.04 to 12.04. how to have same PERL modules there? On 12-06-05 04:00 PM, Rajeev Prasad wrote: > for e.g. > on 10.10: perl ver is: v5.10 > on 12.04 it is: perl (5.14.2-6ubuntu2) > > is there a quick method to do that? No, but you can adapt this algorithm: http://onionstand.blogspot.ca/2012/05/moving-modules-across-perlbrew.html Use this command to create the list of installed modules: $ perl -MExtUtils::Installed -E 'print "$_\n" for ExtUtils::Installed->new->modules' > /tmp/installed.list Copy installed.list to the target system, install `cpanm` and then use this commnad to install them: $ cat /tmp/installed.list | cpanm --interactive -- Just my 0.0002 million dollars worth, Shawn Programming is as much about organization and communication as it is about coding. _Perl links_ official site : http://www.perl.org/ beginners' help : http://learn.perl.org/faq/beginners.html advance help : http://perlmonks.org/ documentation : http://perldoc.perl.org/ news : http://perlsphere.net/ repository : http://www.cpan.org/ blog : http://blogs.perl.org/ regional groups : http://www.pm.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
moving from ubuntu 10.04 to 12.04. how to have same PERL modules there?
Hello, I am going to move (not upgrade) from my current ubuntu ver 10.10 to ver. 12.04 (fresh install). I will restore my data and scripts there and have them ready. But, how do i have all the required modules (which i have installed on my current PC over months) installed on target system? I do not want to have old versions of software on new PC, buut i just want to make sure that all which was installed (in regard to PERL) on old PC should be on new PC as well. for e.g. on 10.10: perl ver is: v5.10 on 12.04 it is: perl (5.14.2-6ubuntu2) is there a quick method to do that? thank you. Rajeev
has anyone used perl CGI scripts with Hiawatha web server?
Anyone has any experience to share about implementing perl CGI scripts on Hiawatha web server? ty. R
Re: need guidance on encode JSON and sorting
i changed and not getting error anymore but the list is still not sorted. my $json = JSON::XS->new; $json->get_canonical; $return_json_text = $json->encode ($tmp_hash); <---no error, but does not produce sorted output the key is a datetime field e.g.: 2012-01-20 22:24:36 value is some text - Original Message - From: Rajeev Prasad To: perl list Cc: Sent: Sunday, February 5, 2012 10:20 PM Subject: Re: need guidance on encode JSON and sorting I tried below but getting err: my $json = JSON::XS->new; $json->get_canonical; $return_json_text = $json->encode $tmp_hash; Scalar found where operator expected atscript.pl line 80, near "->encode $tmp_hash" ??? - Original Message - From: Rajeev Prasad To: perl list Cc: Sent: Sunday, February 5, 2012 10:04 PM Subject: need guidance on encode JSON and sorting in the script this is all i am using JSON as: ... use JSON::XS; ... $return_json_text = encode_json $tmp_hash; this variable ($return_json_text) is then used to display values. I need this to be orderd, but not able to figure how to order the outcome??? I read about $enabled = $json->get_canonical on JSON's page but not sure hot use it as i do not have $json or such object created. Also I am assuming it would be sorted on key field of the JSON hash. ty. Rajeev -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: need guidance on encode JSON and sorting
I tried below but getting err: my $json = JSON::XS->new; $json->get_canonical; $return_json_text = $json->encode $tmp_hash; Scalar found where operator expected atscript.pl line 80, near "->encode $tmp_hash" ??? - Original Message ----- From: Rajeev Prasad To: perl list Cc: Sent: Sunday, February 5, 2012 10:04 PM Subject: need guidance on encode JSON and sorting in the script this is all i am using JSON as: ... use JSON::XS; ... $return_json_text = encode_json $tmp_hash; this variable ($return_json_text) is then used to display values. I need this to be orderd, but not able to figure how to order the outcome??? I read about $enabled = $json->get_canonical on JSON's page but not sure hot use it as i do not have $json or such object created. Also I am assuming it would be sorted on key field of the JSON hash. ty. Rajeev -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
need guidance on encode JSON and sorting
in the script this is all i am using JSON as: ... use JSON::XS; ... $return_json_text = encode_json $tmp_hash; this variable ($return_json_text) is then used to display values. I need this to be orderd, but not able to figure how to order the outcome??? I read about $enabled = $json->get_canonical on JSON's page but not sure hot use it as i do not have $json or such object created. Also I am assuming it would be sorted on key field of the JSON hash. ty. Rajeev -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
DBIx::Class add rows to table, confusion in perldoc example....
Author says: Adding and removing rows To create a new record in the database, you can use the create method. It returns an instance of My::Schema::Result::Album that can be used to access the data in the new record: my $new_album = $schema->resultset('Album')->create({ title => 'Wish You Were Here', artist => 'Pink Floyd' }); Now you can add data to the new record: $new_album->label('Capitol'); $new_album->year('1975'); $new_album->update; But the tables album has only three columns which are: "album" table with three columns: "albumid", "artist", and "title" so what does year and label stand for? sorry i am confused. do i have to run update after running create? ty. Rajeev -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Net::Openssh and sudo?
Hi Salva, thx, but the installed sudo version does not have -S option. so i am not sure how will i then pass the password CU Sudo version 1.5.7p2 sudo -V | -h | -l | -v | -k | -H | [-b] [-p prompt] [-u username/#uid] -s | From: Salvador Fandiño To: beginners@perl.org Sent: Sunday, January 22, 2012 11:08 AM Subject: Re: Net::Openssh and sudo? On 01/20/2012 08:10 PM, Rajeev Prasad wrote: > > > hello, > > using Net::Openssh how can i use sudo to become some other user (say root) on > a target machine and then execute a series of commands as root? > > i looked and tried to use the expect example given on Net::Openssh page but > could not make it to work. > > my $myssh = Net::OpenSSH->new($host, > port => $SSHPORT, > user => $USER, > password => $PASS,) > > now how can i execute a sudo on this, thus becoming a different user and, > then execute bunch of commands on this handle? Have you see the FAQ entry "Running remote commands with sudo" on the module documentation? https://metacpan.org/module/Net::OpenSSH#FAQ It describes a simple way to run commands with sudo that doesn't require Expect. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Net::Openssh and sudo? SOLVED
finally, if anyone needs, here is one which logs on to a remote host as yourself then su to root then run as many commands you wish. saves output in log you can later use. #!/usr/bin/perl # see http://perlmonks.org/?node_id=890441 use strict; use warnings; use Net::OpenSSH; use Expect; $Expect::Exp_Internal = 1; @ARGV == 2 or die <new($host, passwd => $pass1); $ssh->error and die "unable to connect to remote host: " . $ssh->error; #$ssh->system("sudo -k"); my ( $pty, $pid ) = $ssh->open2pty({stderr_to_stdout => 1}, '/usr/local/bin/sudo', -p => 'runasroot:', 'su', '-') or return "failed to attempt su: $!\n"; my $expect = Expect->init($pty); $expect->log_file("expect.pm_log", "w"); my @cmdlist =("ls -l","pwd","ls","who am i","id","whoami"); foreach my $cmd (@cmdlist){ $expect->expect(2, [ qr/runasroot:/ => sub { shift->send("$pass1\n");} ], #use pass2 if using only su [ qr/Sorry/ => sub { die "Login failed" } ], [ qr/#/ => sub { shift->send("$cmd \n");}] ) or die "___Timeout!"; } $expect->expect(2); From: Rajeev Prasad To: perl list Sent: Friday, January 20, 2012 4:26 PM Subject: Re: Net::Openssh and sudo? made some progress: version 3 following is working but it keep running the ls -l in loop, i have to ctrl+C it #!/usr/bin/perl # see http://perlmonks.org/?node_id=890441 use strict; use warnings; use Net::OpenSSH; use Expect; $Expect::Exp_Internal = 1; @ARGV == 2 or die <new($host, passwd => $pass1); $ssh->error and die "unable to connect to remote host: " . $ssh->error; #$ssh->system("sudo -k"); my ( $pty, $pid ) = $ssh->open2pty({stderr_to_stdout => 1}, '/usr/local/bin/sudo', -p => 'runasroot:', 'su', '-') or return "failed to attempt su: $!\n"; my $expect = Expect->init($pty); $expect->log_file("expect.pm_log", "w"); $expect->expect(2, [ qr/runasroot:/ => sub { shift->send("$pass1\n"); exp_continue;} ], #use pass2 if using only su [ qr/Sorry/ => sub { die "Login failed" } ], [qr/#/ => sub { shift->send("ls -l\n"); exp_continue;}] ) or die "___Timeout!"; __END__ From: Rajeev Prasad To: perl list Sent: Friday, January 20, 2012 4:14 PM Subject: Re: Net::Openssh and sudo? found following which is working to the point where i can get to the root prompt, but not sure why any command after that is not working can anyone give any hint? thank you. CODE: #!/usr/bin/perl # see http://perlmonks.org/?node_id=890441 use strict; use warnings; use Net::OpenSSH; use Expect; #$Expect::Exp_Internal = 1; @ARGV == 2 or die <new($host, passwd => $pass1); $ssh->error and die "unable to connect to remote host: " . $ssh->error; #$ssh->system("sudo -k"); my ( $pty, $pid ) = $ssh->open2pty({stderr_to_stdout => 1}, '/usr/local/bin/sudo', -p => 'runasroot:', 'su', '-') or return "failed to attempt su: $!\n"; my $expect = Expect->init($pty); $expect->log_file("expect.pm_log", "w"); $expect->expect(2, [ qr/runasroot:/ => sub { shift->send("$pass1\n");} ], #use pass2 if using only su [ qr/Sorry/ => sub { die "Login failed" } ]); $expect->send("\n\n\n"); $expect->expect(2,[ qr/#/ => sub { shift->send("ls -l\n");} ]) #use pass2 if using only su in above the ls command is not working if i do exp interactive that works fine From: Rajeev Prasad To: perl list Sent: Friday, January 20, 2012 1:10 PM Subject: Net::Openssh and sudo? hello, using Net::Openssh how can i use sudo to become some other user (say root) on a target machine and then execute a series of commands as root? i looked and tried to use the expect example given on Net::Openssh page but could not make it to work. my $myssh = Net::OpenSSH->new($host, port => $SSHPORT, user => $USER, password => $PASS,) now how can i execute a sudo on this, thus becoming a different user and, then execute bunch of commands on this handle? please advice. thank you. Rajeev -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Net::Openssh and sudo? made some progress: version 3
following is working but it keep running the ls -l in loop, i have to ctrl+C it #!/usr/bin/perl # see http://perlmonks.org/?node_id=890441 use strict; use warnings; use Net::OpenSSH; use Expect; $Expect::Exp_Internal = 1; @ARGV == 2 or die <new($host, passwd => $pass1); $ssh->error and die "unable to connect to remote host: " . $ssh->error; #$ssh->system("sudo -k"); my ( $pty, $pid ) = $ssh->open2pty({stderr_to_stdout => 1}, '/usr/local/bin/sudo', -p => 'runasroot:', 'su', '-') or return "failed to attempt su: $!\n"; my $expect = Expect->init($pty); $expect->log_file("expect.pm_log", "w"); $expect->expect(2, [ qr/runasroot:/ => sub { shift->send("$pass1\n"); exp_continue;} ], #use pass2 if using only su [ qr/Sorry/ => sub { die "Login failed" } ], [qr/#/ => sub { shift->send("ls -l\n"); exp_continue;}] ) or die "___Timeout!"; __END__ From: Rajeev Prasad To: perl list Sent: Friday, January 20, 2012 4:14 PM Subject: Re: Net::Openssh and sudo? found following which is working to the point where i can get to the root prompt, but not sure why any command after that is not working can anyone give any hint? thank you. CODE: #!/usr/bin/perl # see http://perlmonks.org/?node_id=890441 use strict; use warnings; use Net::OpenSSH; use Expect; #$Expect::Exp_Internal = 1; @ARGV == 2 or die <new($host, passwd => $pass1); $ssh->error and die "unable to connect to remote host: " . $ssh->error; #$ssh->system("sudo -k"); my ( $pty, $pid ) = $ssh->open2pty({stderr_to_stdout => 1}, '/usr/local/bin/sudo', -p => 'runasroot:', 'su', '-') or return "failed to attempt su: $!\n"; my $expect = Expect->init($pty); $expect->log_file("expect.pm_log", "w"); $expect->expect(2, [ qr/runasroot:/ => sub { shift->send("$pass1\n");} ], #use pass2 if using only su [ qr/Sorry/ => sub { die "Login failed" } ]); $expect->send("\n\n\n"); $expect->expect(2,[ qr/#/ => sub { shift->send("ls -l\n");} ]) #use pass2 if using only su in above the ls command is not working if i do exp interactive that works fine From: Rajeev Prasad To: perl list Sent: Friday, January 20, 2012 1:10 PM Subject: Net::Openssh and sudo? hello, using Net::Openssh how can i use sudo to become some other user (say root) on a target machine and then execute a series of commands as root? i looked and tried to use the expect example given on Net::Openssh page but could not make it to work. my $myssh = Net::OpenSSH->new($host, port => $SSHPORT, user => $USER, password => $PASS,) now how can i execute a sudo on this, thus becoming a different user and, then execute bunch of commands on this handle? please advice. thank you. Rajeev -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Net::Openssh and sudo?
found following which is working to the point where i can get to the root prompt, but not sure why any command after that is not working can anyone give any hint? thank you. CODE: #!/usr/bin/perl # see http://perlmonks.org/?node_id=890441 use strict; use warnings; use Net::OpenSSH; use Expect; #$Expect::Exp_Internal = 1; @ARGV == 2 or die <new($host, passwd => $pass1); $ssh->error and die "unable to connect to remote host: " . $ssh->error; #$ssh->system("sudo -k"); my ( $pty, $pid ) = $ssh->open2pty({stderr_to_stdout => 1}, '/usr/local/bin/sudo', -p => 'runasroot:', 'su', '-') or return "failed to attempt su: $!\n"; my $expect = Expect->init($pty); $expect->log_file("expect.pm_log", "w"); $expect->expect(2, [ qr/runasroot:/ => sub { shift->send("$pass1\n");} ], #use pass2 if using only su [ qr/Sorry/ => sub { die "Login failed" } ]); $expect->send("\n\n\n"); $expect->expect(2,[ qr/#/ => sub { shift->send("ls -l\n");} ]) #use pass2 if using only su in above the ls command is not working if i do exp interactive that works fine From: Rajeev Prasad To: perl list Sent: Friday, January 20, 2012 1:10 PM Subject: Net::Openssh and sudo? hello, using Net::Openssh how can i use sudo to become some other user (say root) on a target machine and then execute a series of commands as root? i looked and tried to use the expect example given on Net::Openssh page but could not make it to work. my $myssh = Net::OpenSSH->new($host, port => $SSHPORT, user => $USER, password => $PASS,) now how can i execute a sudo on this, thus becoming a different user and, then execute bunch of commands on this handle? please advice. thank you. Rajeev -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Net::Openssh and sudo?
hello, using Net::Openssh how can i use sudo to become some other user (say root) on a target machine and then execute a series of commands as root? i looked and tried to use the expect example given on Net::Openssh page but could not make it to work. my $myssh = Net::OpenSSH->new($host, port => $SSHPORT, user => $USER, password => $PASS,) now how can i execute a sudo on this, thus becoming a different user and, then execute bunch of commands on this handle? please advice. thank you. Rajeev -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: 32 bitx Hex point code to 24 bit (8-8-8) point code
Hi John, thx, but when i am using it in a script i am getting error, from CLI the same input is recognized as numeric and i get proper output. here it is: i am getting the input value by splitting a string to an array. does split function makes the array values character? $string = a:b:1:2:0x00D70803:0x00FE3490; @myarr=split(/:/,$string); my $lpc= join "-", map ord, ( split //, pack "N", $myarr[4] )[ -3 .. -1 ]; this is throwing error: Argument "0x00D70803" isn't numeric in pack at ./pc.converter.pl line 11. I also tried to use int() function by specifying int($myarr[4]) but i still get same error ?? From: John W. Krahn To: Perl Beginners Sent: Monday, January 9, 2012 4:57 PM Subject: Re: 32 bitx Hex point code to 24 bit (8-8-8) point code Rajeev Prasad wrote: > Hello John, > > example from SS7 point codes: > > input would be: 32 bit hex value like: 0x00FE3453 > > output expected is 24 bit value (format 8-8-8): 254-52-83 $ perl -le' my $input = 0x00FE3453; print join "-", map ord, ( split //, pack "N", $input )[ -3 .. -1 ]; ' 254-52-83 John -- Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction. -- Albert Einstein -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: supressing error message Use of uninitialized value in concatenation....
Thank you, the following worked: { no warnings qw(uninitialized); ... } - Original Message - From: Jim Gibson To: perl list Cc: Sent: Monday, January 9, 2012 1:14 PM Subject: Re: supressing error message Use of uninitialized value in concatenation On 1/9/12 Mon Jan 9, 2012 10:53 AM, "Rajeev Prasad" scribbled: > Hello, > > I have a lot of fields being concatenated to form a string and sometimes the > values are empty, so i am getting this error: > > Use of uninitialized value in concatenation (.) or string at ./script.pl line > 144, <$IN_FH> line 1. > > how can i suppress this? > > my logic flow: > > > $string1 = "a,b,c,d,e,f, a very long record" > > i only want few fields from this record of hundreds of fields, so > > @array = split(/,/,$string1) > > then reassemble the array elements into the new string: > > $string2 = $array[3]." ".$array[7]." ".$array[24] and so on > > so whenever anything like $array[24] is empty and it occurs in concatenation > above i get this error: > > Use of uninitialized value in concatenation (.) or string at ./script.pl line > 144, <$IN_FH> line 1. > > how to suppress or avoid this error? You can use the 'no warnings uninitialized' pragma within a block to suppress the warnings: { no warnings uninitialed; $string2 = $array[3] . " " . $array[7] . " " . $array[24]; } You could also assign empty strings to undefined array members before the concatenation: $_ = (defined $_ ? $_ : '') for @array; For later Perls: $_ //= '' for @array; If elements of the array returned by split are really undefined, then you must be processing lines that do not have as many fields as you think they do. You could add tests to see how many elements are in @array and process them appropriately if they are short some fields. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: rows to columns issue
Thank you Jim, I changed my approach to array of array. I am getting right result but something seem to be messed up $ cat testfile123 a b c d e f 1 2 3 4 5 6 $ row2col.pl testfile123 Use of uninitialized value in concatenation (.) or string at ./row2col.pl line 29. a 1 Use of uninitialized value in concatenation (.) or string at ./row2col.pl line 29. b 2 Use of uninitialized value in concatenation (.) or string at ./row2col.pl line 29. c 3 Use of uninitialized value in concatenation (.) or string at ./row2col.pl line 29. d 4 Use of uninitialized value in concatenation (.) or string at ./row2col.pl line 29. e 5 Use of uninitialized value in concatenation (.) or string at ./row2col.pl line 29. f 6 Use of uninitialized value in concatenation (.) or string at ./row2col.pl line 29. Use of uninitialized value in concatenation (.) or string at ./row2col.pl line 29. Use of uninitialized value in concatenation (.) or string at ./row2col.pl line 29. CODE: #!/usr/bin/perl use strict; use warnings; my $rowfile= $ARGV[0]; my @aoa; open (my $IN_FH,"<",$rowfile) or die "could not open $rowfile: $!"; my $row=0; my $col=0; while (my $line = <$IN_FH>) { chomp($line); my @tmp=split(/ /,$line); for (my $y=0;$y<=@tmp;$y++) { $aoa[$row][$y] = $tmp[$y]; } $row++; if ( @tmp > $col) { $col = @tmp;} } close $IN_FH; for (my $x=0;$x<=$col;$x++) { for (my $y=0;$y<=$row;$y++) { print $aoa[$y][$x]." "; } print "\n"; } - Original Message - From: Jim Gibson To: perl list Cc: Sent: Monday, January 9, 2012 3:29 PM Subject: Re: rows to columns issue On 1/9/12 Mon Jan 9, 2012 1:08 PM, "Rajeev Prasad" scribbled: > > > Hello, > > I tried following code but it is not working. > > I have a file with many lines(records) where field separator is space. > > I want to convert rows to columns, something like... > > source: > a b c d > 1 2 3 4 > > output: > a 1 > b 2 > c 3 > d 4 > > > > Here is my test code: It is not working :( It would be helpful if you could tell us exactly how it is not working. Does the program not compile? Does is not produce an output file? Is the output file not what you expect? Do you get an error message when you run it? > #!/usr/bin/perl > > use strict; > use warnings; > > my ($IN_FH, $line,$string); It is better to declare these three variables when they are first used. > > my $rowfile= $ARGV[0]; > my $colfile= $rowfile.".row2col"; > > open ($IN_FH,"<",$rowfile) or die "could not open $rowfile: $!"; > #open ($OUT_FH,">",$colfile) or die "could not open $colfile: $!"; > > my $counter=1; > while ($line = ) { That should be <$IN_FH>. IN_FH and $IN_FH are two different things. > chomp($line); > my @arr_."$counter"=split(/ /,$line); I do not know what the above line does or is supposed to do. Are you trying to use dynamically-generated variable names? That is rarely a good idea. Use an array-of-arrays instead. > $counter++; > } > close $IN_FH; > > for (my $i=1;$i<=150;$i++) { > for (my $x=1;$x<=$counter;$x++) { > $string .= $arr_."$x".[$i]." "; > } > print $string; > } -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
rows to columns issue
Hello, I tried following code but it is not working. I have a file with many lines(records) where field separator is space. I want to convert rows to columns, something like... source: a b c d 1 2 3 4 output: a 1 b 2 c 3 d 4 Here is my test code: It is not working :( #!/usr/bin/perl use strict; use warnings; my ($IN_FH, $line,$string); my $rowfile= $ARGV[0]; my $colfile= $rowfile.".row2col"; open ($IN_FH,"<",$rowfile) or die "could not open $rowfile: $!"; #open ($OUT_FH,">",$colfile) or die "could not open $colfile: $!"; my $counter=1; while ($line = ) { chomp($line); my @arr_."$counter"=split(/ /,$line); $counter++; } close $IN_FH; for (my $i=1;$i<=150;$i++) { for (my $x=1;$x<=$counter;$x++) { $string .= $arr_."$x".[$i]." "; } print $string; } -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
supressing error message Use of uninitialized value in concatenation....
Hello, I have a lot of fields being concatenated to form a string and sometimes the values are empty, so i am getting this error: Use of uninitialized value in concatenation (.) or string at ./script.pl line 144, <$IN_FH> line 1. how can i suppress this? my logic flow: $string1 = "a,b,c,d,e,f, a very long record" i only want few fields from this record of hundreds of fields, so @array = split(/,/,$string1) then reassemble the array elements into the new string: $string2 = $array[3]." ".$array[7]." ".$array[24] and so on so whenever anything like $array[24] is empty and it occurs in concatenation above i get this error: Use of uninitialized value in concatenation (.) or string at ./script.pl line 144, <$IN_FH> line 1. how to suppress or avoid this error? ty. R -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: 32 bitx Hex point code to 24 bit (8-8-8) point code
Hello John, example from SS7 point codes: input would be: 32 bit hex value like: 0x00FE3453 output expected is 24 bit value (format 8-8-8): 254-52-83 ty. R From: John W. Krahn To: Perl Beginners Sent: Monday, January 9, 2012 3:31 AM Subject: Re: 32 bitx Hex point code to 24 bit (8-8-8) point code Rajeev Prasad wrote: > > Hello, Hello, > I am trying to convert 32 bitx Hex point code to 24 bit (8-8-8) point > code. What does the input look like and what do you expect the corresponding output to look like? > i tried to use below script from net, but due to limited > understanding of perl and above script, I was not able to resolve my > problem. If you wish to post code then please post plain ASCII text. The code you posted had Unicode characters that were unrecognized by perltidy. John -- Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction. -- Albert Einstein -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
32 bitx Hex point code to 24 bit (8-8-8) point code
Hello, I am trying to convert 32 bitx Hex point code to 24 bit (8-8-8) point code. i tried to use below script from net, but due to limited understanding of perl and above script, I was not able to resolve my problem. Can someone please help me resolve my issue? thank you. Rajeev #!/usr/bin/perl -w my $decimalcode = shift; my $binarycode = 0b0; my @ciscocode ; $binarycode = unpack(”B32″,pack(”N”,$decimalcode)); my @itucode = grep {$_ ne ”} split(/(\d{18})(\d{3})(\d{8})(\d{3})/,$binarycode); my @ansicode = grep {$_ ne ”} split(/(\d{8})(\d{8})(\d{8})(\d{8})/,$binarycode); print “itucode = $itucode[1] $itucode[2] $itucode[3]\n”; print “ansicode = $ansicode[1] $ansicode[2] $ansicode[3]\n”; my $bintest = unpack(”N”,pack(”B32″,substr(”0″ x 32 . $binarycode, -32))); printf (”Decimal Code = [%05d]\n”,$bintest); @ciscocode = (unpack(”N”,pack(”B32″,substr(”0″ x 32 . $itucode[1], -32))), unpack(”N”,pack(”B32″,substr(”0″ x 32 . $itucode[2], -32))), unpack(”N”,pack(”B32″,substr(”0″ x 32 . $itucode[3], -32; printf (”ITU Cisco Code = %03d-%03d-%03d\n”, $ciscocode[0],$ciscocode[1],$ciscocode[2]); @ciscocode = (unpack(”N”,pack(”B32″,substr(”0″ x 32 . $ansicode[1], -32))), unpack(”N”,pack(”B32″,substr(”0″ x 32 . $ansicode[2], -32))), unpack(”N”,pack(”B32″,substr(”0″ x 32 . $ansicode[3], -32; printf (”ANSI Cisco Codec = %03d-%03d-%03d\n”, $ciscocode[0],$ciscocode[1],$ciscocode[2]); -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
tinyMCE as web editor for editing code?
Hello, Has anyone ever used, tinyMCE as web based editor (to run inside the browser) to edit the perl/php/shell scripts on the server? I am looking for some direction and advice? thank you. Rajeev -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Guidance for a New Programmer/Perl User
Shlomi, all of you said is correct, but some may get a negative impression. it shows as if perl5 and perl 6 are two very different. perl5 is dead end (coz perl 6 is not like 5), perl6 which is in making for so long is still not ready. for a new person, this could mean less confidence in perl and more interest towards php etc... ty. Rajeev From: Shlomi Fish To: Brendan Cc: Rajeev Prasad ; Mark Tiesman ; "beginners@perl.org" Sent: Thursday, December 15, 2011 2:45 PM Subject: Re: Guidance for a New Programmer/Perl User Hi Rajeev, On Thu, 15 Dec 2011 15:20:24 -0500 Brendan wrote: > How quickly Perl 6 knowledge can be put to good use probably depends on where > you work. I don't think there are many businesses where they are looking to > convert their Perl 5 code to Perl 6 in the immediate future. > Rajeev may wish to read http://perl-begin.org/learn/perl6/ about the relationship between Perl 5/"perl 5" and Perl 6. Neither Perl 5 nor perl 5 are going away, and Perl 6 is a completely different language. Furthermore, the current Perl 6 implementations are incomplete (= don't implement the entire Perl 6 spec), and may not perform very well or have various bugs. I wouldn't want to discourage you from learning Perl 6, because it's an interesting language with many nifty features, but learning Perl 5 now will still prove useful for a very long term. Regards, Shlomi Fish > Rajeev Prasad wrote: > > >Mark, > > > >i think with an eye on future, you should start by reading Rakudo etc. i.e. > >perl6 -- - Shlomi Fish http://www.shlomifish.org/ Stop Using MSIE - http://www.shlomifish.org/no-ie/ There is no IGLU Cabal! Home‐made Cabals eventually superseded the power and influence of the original IGLU Cabal, which was considered a cutting edge development at its time. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Guidance for a New Programmer/Perl User
Mark, i think with an eye on future, you should start by reading Rakudo etc. i.e. perl6 From: Mark Tiesman To: beginners@perl.org Sent: Thursday, December 15, 2011 9:54 AM Subject: Guidance for a New Programmer/Perl User Hi all. I recently started a job that at some point is going to require me knowing and using Perl. I am pretty green as a programmer and need some guidance to get me going on the right foot. Currently I am reading the Llama book to grease the skids so to speak, but am looking for addition advice, reading material, classes, and general information on learning to program and Perl. Any help provided is GREATLY appreciated. Thanks!! -- Mark -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: extracting email addresses from a file
thx Sheppy, good enough for me. i am a beginner in perl. From: Sheppy R To: Rob Coops Cc: Rajeev Prasad ; perl list Sent: Tuesday, November 29, 2011 9:54 AM Subject: Re: extracting email addresses from a file Couldn't you just use the non-whitespace character to capture everything before and after the @ symbol? s/^.*\s(\S+@\S+)\s.*$/$1/
extracting email addresses from a file
hello, i am trying to extract email address from a afile, but not quite succesful. here is what i have: the file: myterqlqt qntmrq Prqtesm qltul qzeez Smqik qltulqzee...@jmqil.com 976665 myterqlqt qntmrq Prqtesm teepqk Mittql teep...@jmqil.com 939383 Onjole qntmrq Prqtesm lmqrqtm Etqrq cont...@lmqrqteeyqm.orj 9889 Vijqyqwqtq qntmrq Prqtesm Sitmqrtmq si...@msitmu.in 939775777 Visqkmqpqtnqm qntmrq Prqtesm Smyqmprqsqt Mqntri mumqnrijmts...@yqmoo.co.in 9735566 Wqrqnjql qntmrq Prqtesm Smqsmi qrjulq smqsmi.qrj...@jmqil.com 99799 juntur qntmrq Prqtesm Rqvitejq Jqllepqlli rqvte...@jmqil.com 983 jooty qntmrq Prqtesm Sqtti Kumqr ys...@jmqil.com 986663, West jotqvqri (Eluru) qntmrq Prqtesm Rqm Prqsqt rqmprqsqttu...@yqmoo.com 96 59 Mqncmeriql qntmrq Prqtesm Smqntmilql jqmlotm smqntmilql.jqml...@live.com 933565 898575 Kmqmmqm qntmrq Prqtesm Lqksmmqn Rqo jqtipqrtmy jqtipqrt...@jmqil.com Kurnool (Nemru Nqjqr) qntmrq Prqtesm lqntulmqi Iqlql mussqin limuss...@yqmoo.co.in 986, 8958575, 8958575 my attempt: perl -ple 's/^.*\s(\w*@\w*.\w+).*$/$1/' my result: qltulqzee...@jmqil.com teep...@jmqil.com cont...@lmqrqteeyqm.orj si...@msitmu.in mumqnrijmts...@yqmoo.co Wqrqnjql qntmrq Prqtesm Smqsmi qrjulq smqsmi.qrj...@jmqil.com 99799 rqvte...@jmqil.com ys...@jmqil.com rqmprqsqttu...@yqmoo.com Mqncmeriql qntmrq Prqtesm Smqntmilql jqmlotm smqntmilql.jqml...@live.com 933565 898575 jqtipqrt...@jmqil.com limuss...@yqmoo.co please advise how should be my regex? thx.
Re: using WWW::Mechanize why am i getting this proxy issue?
In my WWW:Mechanize script below, can someone please advice why am i getting proxy issue. when the same proxy is working fine with LWP::UserAgent in a different script. (both scripts are given below) thank you. Rajeev From: Rajeev Prasad To: perl list Sent: Tuesday, November 22, 2011 3:43 PM Subject: using WWW::Mechanize thru proxy to https(SSL) with website/form authentication, proxy error!! Here is the prob description in short: 1. post your url in browser: https://myrel/files/file.doc 2. you get a logon page (URL still looking same) 3. enter field names: username/password 4. press 'ok' button (name = bsubmit) after successful login: 5. you get new page: https://myurl/pagSuccess/ 6. you have to click 'ok' ( field name = successbtn ) on this page now to go back to where you wanted to go... 7. then you get a firefox dialog: where you have to select (radio button) 'Save File' press ok 8. you are done!!! (saves the file to default location) here is the script so far: #!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; #print "Content-type: text/html\n\n"; my $username = "myid"; my $password = "mypass"; my $outfile = "testout.doc"; $ENV{HTTPS_PROXY} = 'http://myproxy:8080'; my $mech = WWW::Mechanize->new(noproxy =>'0'); my $url = 'https://myurl/files/file.doc'; $mech->get($url); $mech->form_name('frmLogin'); $mech->field(username => "$username"); $mech->field(password => "$password"); $mech->click('bsubmit'); $mech->click('successbtn'); # here i am hoping this will click the 'ok' button the next page my $response = $mech->content(); open(OUTFILE, ">$outfile"); print OUTFILE "$response"; close(OUTFILE); error i am getting: Error GETing https://myurl/files/file.doc: proxy connect failed: PROXY ERROR HEADER, could be non-SSL URL: HTTP/1.0 504 Gateway Time-out Server: squid/ Date: Content-Type: text/html Content-Length: 1117 X-Squid-Error: ERR_CONNECT_FAIL 238 ... ... but the following works thru SAME proxy(it fails to do any form based authentication i guess)??? #!/usr/bin/perl use strict; use warnings; use LWP; my $ua = LWP::UserAgent->new; my $agent = "my-lwp agent"; $ua->agent($agent); $ENV{HTTPS_PROXY} = 'http://myproxy:8080'; $ENV{HTTP_PROXY} = 'http://myproxy:8080'; my $req = HTTP::Request->new(GET => 'https://mail.yahoo.com'); $req->content_type('text/html'); $req->protocol('HTTP/1.0'); my $response = $ua->request($req); if ($response->is_success) { print "1 success\n"; } else { print "1 error\n"; } print $response->status_line;
using WWW::Mechanize thru proxy to https(SSL) with website/form authentication, proxy error!!
Here is the prob description in short: 1. post your url in browser: https://myrel/files/file.doc 2. you get a logon page (URL still looking same) 3. enter field names: username/password 4. press 'ok' button (name = bsubmit) after successful login: 5. you get new page: https://myurl/pagSuccess/ 6. you have to click 'ok' ( field name = successbtn ) on this page now to go back to where you wanted to go... 7. then you get a firefox dialog: where you have to select (radio button) 'Save File' press ok 8. you are done!!! (saves the file to default location) here is the script so far: #!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; #print "Content-type: text/html\n\n"; my $username = "myid"; my $password = "mypass"; my $outfile = "testout.doc"; $ENV{HTTPS_PROXY} = 'http://myproxy:8080'; my $mech = WWW::Mechanize->new(noproxy =>'0'); my $url = 'https://myurl/files/file.doc'; $mech->get($url); $mech->form_name('frmLogin'); $mech->field(username => "$username"); $mech->field(password => "$password"); $mech->click('bsubmit'); $mech->click('successbtn'); # here i am hoping this will click the 'ok' button the next page my $response = $mech->content(); open(OUTFILE, ">$outfile"); print OUTFILE "$response"; close(OUTFILE); error i am getting: Error GETing https://myurl/files/file.doc: proxy connect failed: PROXY ERROR HEADER, could be non-SSL URL: HTTP/1.0 504 Gateway Time-out Server: squid/ Date: Content-Type: text/html Content-Length: 1117 X-Squid-Error: ERR_CONNECT_FAIL 238 ... ... but the following works thru SAME proxy(it fails to do any form based authentication i guess)??? #!/usr/bin/perl use strict; use warnings; use LWP; my $ua = LWP::UserAgent->new; my $agent = "my-lwp agent"; $ua->agent($agent); $ENV{HTTPS_PROXY} = 'http://myproxy:8080'; $ENV{HTTP_PROXY} = 'http://myproxy:8080'; my $req = HTTP::Request->new(GET => 'https://mail.yahoo.com'); $req->content_type('text/html'); $req->protocol('HTTP/1.0'); my $response = $ua->request($req); if ($response->is_success) { print "1 success\n"; } else { print "1 error\n"; } print $response->status_line;
Re: module is installed but getting error
thanks, that was the quickest resolve for me on this LIST ever. thank you! From: Kenneth Wolcott To: Rajeev Prasad Cc: perl list Sent: Tuesday, November 22, 2011 2:35 PM Subject: Re: module is installed but getting error On Tue, Nov 22, 2011 at 12:31, Rajeev Prasad wrote: > getting this error: > > Can't locate Http/Cookies.pm in @INC (@INC contains: /etc/perl > /usr/local/lib/perl/5.10.1 /usr/local/share/perl/5.10.1 /usr/lib/perl5 > /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 > /usr/local/lib/site_perl .) at ./testscript.pl line 7. > > > module was installed at: > > # make install > Installing /usr/local/share/perl/5.10.1/HTTP/Cookies.pm > Installing /usr/local/share/perl/5.10.1/HTTP/Cookies/Netscape.pm > Installing /usr/local/share/perl/5.10.1/HTTP/Cookies/Microsoft.pm > Installing /usr/local/man/man3/HTTP::Cookies::Netscape.3pm > Installing /usr/local/man/man3/HTTP::Cookies::Microsoft.3pm > Installing /usr/local/man/man3/HTTP::Cookies.3pm > Appending installation info to /usr/local/lib/perl/5.10.1/perllocal.pod > > > OS is ubuntu > > script says: use Http::Cookies > > > @INC path does contain /usr/local/share/perl/5.10.1 so will it not pick > anything under that folder? > Case-sensitive? Try HTTP::Cookies? Ken Wolcott
module is installed but getting error
getting this error: Can't locate Http/Cookies.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.10.1 /usr/local/share/perl/5.10.1 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .) at ./testscript.pl line 7. module was installed at: # make install Installing /usr/local/share/perl/5.10.1/HTTP/Cookies.pm Installing /usr/local/share/perl/5.10.1/HTTP/Cookies/Netscape.pm Installing /usr/local/share/perl/5.10.1/HTTP/Cookies/Microsoft.pm Installing /usr/local/man/man3/HTTP::Cookies::Netscape.3pm Installing /usr/local/man/man3/HTTP::Cookies::Microsoft.3pm Installing /usr/local/man/man3/HTTP::Cookies.3pm Appending installation info to /usr/local/lib/perl/5.10.1/perllocal.pod OS is ubuntu script says: use Http::Cookies @INC path does contain /usr/local/share/perl/5.10.1 so will it not pick anything under that folder?
best module to download files from https
hello, what would be the best module to download a file from an https://url ? I am trying to download some files over secured website and am willing to try the most correct (no overkill) module for the job. task: to download files from secured websites, using perl script: https://myurl/file.doc https://myurl/ needs username password and sets a cookie too, which expires in 24 hours. so far i tried: which is failing me on how to submit username and password and also accept the cookie. thx in advance. #!/usr/bin/perl use strict; use warnings; use LWP; use Data::Dumper; my $ua = LWP::UserAgent->new; my $agent = "my-lwp agent"; $ua->agent($agent); $ENV{HTTPS_PROXY} = 'http://myproxy:8080'; my $req = HTTP::Request->new(GET => 'https://myurl/file.doc'); $req->content_type('text/html'); $req->protocol('HTTP/1.0'); #try use an oder version my $response = $ua->request($req); # add , 'teste_https.html' to save with a name... if ($response->is_success) { print "1 success\n"; #$response->decoded_content; # or whatever } else { print "1 error\n"; # die $response->status_line; } print Dumper $response; __END__
Re: is this ssh happenign in parallel? [SOLVED]
the issue was very easily resolved when i discovered Parallel::ForkManager following works wonderfully (excerpt): ... ... my $pm = Parallel::ForkManager->new(10); ... foreach $host (@allhosts) { $pm->start($host) and next; my ($MFSSH) = Net::OpenSSH->new($host, port => $SSHPORT, user => $USER, password => $PASS, default_stderr_fh => $stderr_fh, default_stdout_fh => $stdout_fh, master_opts => [-o => 'StrictHostKeyChecking=no', -o => 'ConnectTimeout 60'], ); $EXITCODE = $MFSSH->error; if ($EXITCODE eq "0") { #go to next host if ssh fails foreach $CMD (@MFCMDS){ chomp($CMD); ( @CMDRESULT, $CMDERR ) = $MFSSH->capture($CMD); print MFOH "\n$host COMMAND: $CMD\n"; foreach my $line (@CMDRESULT) { print MFOH "$host $line"; } @CMDRESULT = ""; if (defined $CMDERR ) {print MFOH "$host $CMDERR \n"; $CMDERR = "";} } } undef $MFSSH; $pm->finish; } ... ... no need to use ssh::parallel From: salvador fandino To: Rajeev Prasad Cc: "beginners@perl.org" Sent: Monday, November 14, 2011 4:20 AM Subject: Re: is this ssh happenign in parallel? On Mon, Nov 14, 2011 at 12:43 AM, Rajeev Prasad wrote: > Salva, > > can you explain how to use variable expansion in your written module > Net::Openssh and Net::Openssh::Parallel ? I want to be able to specify > userid and password for the parallel ssh sessions using > Net::Openssh::Parallel ... There is no relation between the "variable expansion" feature and how you specify the user and password for some host. User and password can be used as follows: $pssh->add_host($host, user => $user, password => $password); - Salva -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: is this ssh happenign in parallel?
Salav thx a lot. I was able to use all the ssh options i need. last thing i need to understand is how to redirect the output to a local file from all the commands: how to redirect the out of the following to a file handle? $pssh->push('*', command => @MFCMDS); I tried: but not working??? @result = $pssh->run; thx. Rajeev From: salva To: beginners@perl.org Sent: Thursday, November 10, 2011 4:51 AM Subject: Re: is this ssh happenign in parallel? On Nov 8, 12:56 am, rp.ne...@yahoo.com (Rajeev Prasad) wrote: > using the async option in Net::OpenSSH > > can someone help me understand whether in second loop commands are being > executed without waiting for them to complete, so that parallelism is > achieved as indicated by using async option? > > if not, then how can we achieve to execute the commands on remote hosts in > parallel using Net::OpenSSH? > > my @hosts =qw(...); #all hosts > my @allcmds = qw(...); #all commands > > for my $host (@hosts){ #loop to process all host in list > chomp($host); > $ssh{$host} = Net::OpenSSH->new($host, > port => $SSHPORT, > user => $USER, > password => $PASS, > default_stderr_fh => $stderr_fh, > default_stdout_fh => $stdout_fh, > async => 1, > master_opts => [-o => 'StrictHostKeyChecking=no', > -o => 'ConnectTimeout 10'], > ); > } > > open(MFOH,">>$MFRESULT"); > > for my $host (@hosts) { > foreach $CMD (@allcmds){ > chomp($CMD); > ( @CMDRESULT, $CMDERR ) = $ssh{$host}->capture("$CMD"); > print MFOH "\n$host COMMAND: $CMD\n"; > foreach my $line (@CMDRESULT) { print MFOH "$host $line"; } > @CMDRESULT = ""; > if (defined $CMDERR ) {print MFOH "$host $CMDERR \n"; $CMDERR = > "";} > } > } > close MFOH; > > The capture method does not work asynchronously. For that you will have to run the commands with the pipe_out method and capture the output of all the commands in parallel using a select loop or POE or AnyEvent. Alternatively use Net::OpenSSH::Parallel -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: is this ssh happenign in parallel?
Salva, can you explain how to use variable expansion in your written module Net::Openssh and Net::Openssh::Parallel ? I want to be able to specify userid and password for the parallel ssh sessions using Net::Openssh::Parallel ... thank you. Rajeev Variable expansion This module activates Net::OpenSSH variable expansion by default. That way, it is possible to easily customize the actions executed on every host in base to some of its properties. For instance: $pssh->push('*', scp_get => "/var/log/messages", "messages.%HOST%"); copies the log files appending the name of the remote hosts to the local file names. The variables HOST, USER, PORT and LABEL are predefined. ________ From: Rajeev Prasad To: salva ; "beginners@perl.org" Sent: Thursday, November 10, 2011 8:50 AM Subject: Re: is this ssh happenign in parallel? Hello Salva, I want to use Net::OpenSSH::Parallel, but i could not figure: 1. how to supply username and password to each connection? 2. can i write output from all sessions to a single local file? thank you. From: salva To: beginners@perl.org Sent: Thursday, November 10, 2011 4:51 AM Subject: Re: is this ssh happenign in parallel? On Nov 8, 12:56 am, rp.ne...@yahoo.com (Rajeev Prasad) wrote: > using the async option in Net::OpenSSH > > can someone help me understand whether in second loop commands are being > executed without waiting for them to complete, so that parallelism is > achieved as indicated by using async option? > > if not, then how can we achieve to execute the commands on remote hosts in > parallel using Net::OpenSSH? > > my @hosts =qw(...); #all hosts > my @allcmds = qw(...); #all commands > > for my $host (@hosts){ #loop to process all host in list > chomp($host); > $ssh{$host} = Net::OpenSSH->new($host, > port => $SSHPORT, > user => $USER, > password => $PASS, > default_stderr_fh => $stderr_fh, > default_stdout_fh => $stdout_fh, > async => 1, > master_opts => [-o => 'StrictHostKeyChecking=no', > -o => 'ConnectTimeout 10'], > ); > } > > open(MFOH,">>$MFRESULT"); > > for my $host (@hosts) { > foreach $CMD (@allcmds){ > chomp($CMD); > ( @CMDRESULT, $CMDERR ) = $ssh{$host}->capture("$CMD"); > print MFOH "\n$host COMMAND: $CMD\n"; > foreach my $line (@CMDRESULT) { print MFOH "$host $line"; } > @CMDRESULT = ""; > if (defined $CMDERR ) {print MFOH "$host $CMDERR \n"; $CMDERR = > "";} > } > } > close MFOH; > > The capture method does not work asynchronously. For that you will have to run the commands with the pipe_out method and capture the output of all the commands in parallel using a select loop or POE or AnyEvent. Alternatively use Net::OpenSSH::Parallel -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: is this ssh happenign in parallel?
Hello Salva, I want to use Net::OpenSSH::Parallel, but i could not figure: 1. how to supply username and password to each connection? 2. can i write output from all sessions to a single local file? thank you. From: salva To: beginners@perl.org Sent: Thursday, November 10, 2011 4:51 AM Subject: Re: is this ssh happenign in parallel? On Nov 8, 12:56 am, rp.ne...@yahoo.com (Rajeev Prasad) wrote: > using the async option in Net::OpenSSH > > can someone help me understand whether in second loop commands are being > executed without waiting for them to complete, so that parallelism is > achieved as indicated by using async option? > > if not, then how can we achieve to execute the commands on remote hosts in > parallel using Net::OpenSSH? > > my @hosts =qw(...); #all hosts > my @allcmds = qw(...); #all commands > > for my $host (@hosts){ #loop to process all host in list > chomp($host); > $ssh{$host} = Net::OpenSSH->new($host, > port => $SSHPORT, > user => $USER, > password => $PASS, > default_stderr_fh => $stderr_fh, > default_stdout_fh => $stdout_fh, > async => 1, > master_opts => [-o => 'StrictHostKeyChecking=no', > -o => 'ConnectTimeout 10'], > ); > } > > open(MFOH,">>$MFRESULT"); > > for my $host (@hosts) { > foreach $CMD (@allcmds){ > chomp($CMD); > ( @CMDRESULT, $CMDERR ) = $ssh{$host}->capture("$CMD"); > print MFOH "\n$host COMMAND: $CMD\n"; > foreach my $line (@CMDRESULT) { print MFOH "$host $line"; } > @CMDRESULT = ""; > if (defined $CMDERR ) {print MFOH "$host $CMDERR \n"; $CMDERR = > "";} > } > } > close MFOH; > > The capture method does not work asynchronously. For that you will have to run the commands with the pipe_out method and capture the output of all the commands in parallel using a select loop or POE or AnyEvent. Alternatively use Net::OpenSSH::Parallel -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: is this ssh happenign in parallel?
Hi, thx for advice, ye sit is part of code, code is working fine. i will fix CAPS on variables soon. quote is fixed. From: Brandon McCaig To: Rajeev Prasad Cc: perl list Sent: Tuesday, November 8, 2011 11:01 AM Subject: Re: is this ssh happenign in parallel? Hello: I'm not familiar with Net::OpenSSH so I can't help with that, but I can point out some questionable code and suggest improvements. On Mon, Nov 07, 2011 at 03:56:17PM -0800, Rajeev Prasad wrote: > my @hosts =qw(...); #all hosts > my @allcmds = qw(...); #all commands I don't think it really makes sense to use the qw operator for a list of commands (unless the commands just happen to not require arguments, but that's rare). :\ I'll just trust that you know what you're doing. :P Otherwise, you should use Data::Dumper to ensure that your @allcmds array is built as expected. > for my $host (@hosts){ #loop to process all host in list > chomp($host); Since you are using the qw operator to assign @hosts it doesn't really make sense to chomp it... I'll assume that you're actually doing something different than what you've shown here. > $ssh{$host} = Net::OpenSSH->new($host, > port => $SSHPORT, > user => $USER, > password => $PASS, > default_stderr_fh => $stderr_fh, > default_stdout_fh => $stdout_fh, > async => 1, > master_opts => [-o => 'StrictHostKeyChecking=no', > -o => 'ConnectTimeout 10'], > ); > } > > > open(MFOH,">>$MFRESULT"); You should generally use lexical file handles and the 3-argument version of open. You should also be checking for and handling the potential failure of open (e.g., with or die) (perhaps you're using autodie instead, but it isn't shown so there's no way to know). > for my $host (@hosts) { > foreach $CMD (@allcmds){ > chomp($CMD); > ( @CMDRESULT, $CMDERR ) = $ssh{$host}->capture("$CMD"); These should probably be lexical variables (but it isn't clear since parts of the program appear to be missing). That suggests also that you aren't using the 'strict' pragma, but you should be. It's possible that you've declared these variables globally, but it doesn't seem warranted. Also, you probably shouldn't be quoting $CMD here since IIRC it can only be a string when assigned with qw. It's useless, potentially wasteful, and in other circumstances potentially erroneous to quote a variable. Also, since @CMDRESULT is an array, it will consume all elements of the list returned by Net::OpenSSH::capture. IOW, $CMDERR can never get a value other than undef from the above assignment. Lastly, it's distracting and probably bad style to use uppercase identifiers here. > print MFOH "\n$host COMMAND: $CMD\n"; > foreach my $line (@CMDRESULT) { print MFOH "$host $line"; } > @CMDRESULT = ""; > if (defined $CMDERR ) {print MFOH "$host $CMDERR \n"; $CMDERR = > "";} This if statement is useless because as mentioned above $CMDERR will never be defined. > } > } > close MFOH; > > HTH, -- Brandon McCaig Castopulence Software <https://www.castopulence.org/> Blog <http://www.bamccaig.com/> perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }. q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.}; tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say'
is this ssh happenign in parallel?
using the async option in Net::OpenSSH can someone help me understand whether in second loop commands are being executed without waiting for them to complete, so that parallelism is achieved as indicated by using async option? if not, then how can we achieve to execute the commands on remote hosts in parallel using Net::OpenSSH? my @hosts =qw(...); #all hosts my @allcmds = qw(...); #all commands for my $host (@hosts){ #loop to process all host in list chomp($host); $ssh{$host} = Net::OpenSSH->new($host, port => $SSHPORT, user => $USER, password => $PASS, default_stderr_fh => $stderr_fh, default_stdout_fh => $stdout_fh, async => 1, master_opts => [-o => 'StrictHostKeyChecking=no', -o => 'ConnectTimeout 10'], ); } open(MFOH,">>$MFRESULT"); for my $host (@hosts) { foreach $CMD (@allcmds){ chomp($CMD); ( @CMDRESULT, $CMDERR ) = $ssh{$host}->capture("$CMD"); print MFOH "\n$host COMMAND: $CMD\n"; foreach my $line (@CMDRESULT) { print MFOH "$host $line"; } @CMDRESULT = ""; if (defined $CMDERR ) {print MFOH "$host $CMDERR \n"; $CMDERR = "";} } } close MFOH;
Re: how to use Net::OpenSSH::Parallel
how do you provide username and password to use to ssh into the remote systems? i am trying to run multiple commands using ssh to remote systems and store output in a local file. From: salva To: beginners@perl.org Sent: Friday, September 16, 2011 1:26 AM Subject: Re: how to use Net::OpenSSH::Parallel On Sep 14, 11:57 pm, rp.ne...@yahoo.com (Rajeev Prasad) wrote: > trying to use this module now. but i guess i have a very basic issue: > > currently i am running following in a loop for all hosts (and a inner loop > for all commands for a host): > > my ($MFSSH) = Net::OpenSSH->new($HOST, > user => $USER, > password => $PASS, > default_stderr_fh => $stderr_fh, > default_stdout_fh => $stdout_fh, > master_opts => [-o => 'StrictHostKeyChecking=no', > -o => 'ConnectTimeout 10'], > ); > $EXITCODE = $MFSSH->error; > next if ($EXITCODE ne "0"); #go to next host if ssh fails > foreach $CMD (@MFCMDS){ > chomp($CMD); > ( @CMDRESULT, $CMDERR ) = $MFSSH->capture("$CMD"); > } > > how can i use Net::OpenSSH::Parallel this script? i mean i understood > creating a new instance like pssh in the module CPAN page, but not sure how > to integrate it with the script i already have. Net::OpenSSH::Parallel does not allow capturing directly the output of commands into perl scalars. You have to redirect it to some file and then reread it. It would be easier to help you if you tells us what you need to do from a higher level. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: LWP::UserAgent 501 Not Implemented only for https?? [firefox works fine]
Hi Gustavo, I tried both, still getting same error. tx. Rajeev From: Gustavo Telly To: Rajeev Prasad Cc: perl list Sent: Thursday, October 20, 2011 11:45 AM Subject: Re: LWP::UserAgent 501 Not Implemented only for https?? [firefox works fine] Hello Rajeev, Did you try: $ua->protocols_allowed( [ 'http', 'https'] ); or $ua->protocols_allowed(undef); ?? 2011/10/20 Rajeev Prasad anyone ? plz > > > > >here is my script which is trying to access two websites, from my linux box. i >am not able to figure, why am i getting "501 Not Implemented" for any https >website. > >especially when the firefox browser from the same box can access the websites >fine using same proxy. proxy does not require username/password authentication. > > >I do have Crypt::SSLeay installed. > > > >#!/usr/bin/perl >use strict; >use warnings; >use LWP::UserAgent; > >my $ua = LWP::UserAgent->new; >$ua->proxy(['https', 'http', 'ftp'], 'http://myproxy.net:8080/'); >$ua->agent('Mozilla/5.0'); > > >my $response = $ua->get( 'http://www.yahoo.com' , ':content_file' => >"testhttp.html" ); > if ($response->is_success) { > print "success\n"; > } > else { > print "error\n"; > # die $response->status_line; > } > >$response = $ua->get('https://mail.yahoo.com', ':content_file' => >'testhttps.html'); > if ($response->is_success) { > print "success\n"; #$response->decoded_content; # or whatever > } > else { > print "error\n"; > die $response->status_line; > }
Re: LWP::UserAgent 501 Not Implemented only for https?? [firefox works fine]
anyone ? plz here is my script which is trying to access two websites, from my linux box. i am not able to figure, why am i getting "501 Not Implemented" for any https website. especially when the firefox browser from the same box can access the websites fine using same proxy. proxy does not require username/password authentication. I do have Crypt::SSLeay installed. #!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->proxy(['https', 'http', 'ftp'], 'http://myproxy.net:8080/'); $ua->agent('Mozilla/5.0'); my $response = $ua->get( 'http://www.yahoo.com' , ':content_file' => "testhttp.html" ); if ($response->is_success) { print "success\n"; } else { print "error\n"; # die $response->status_line; } $response = $ua->get('https://mail.yahoo.com', ':content_file' => 'testhttps.html'); if ($response->is_success) { print "success\n"; #$response->decoded_content; # or whatever } else { print "error\n"; die $response->status_line; }
LWP::UserAgent 501 Not Implemented only for https?? [firefox works fine]
here is my script which is trying to access two websites, from my linux box. i am not able to figure, why am i getting "501 Not Implemented" for any https website. especially when the firefox browser from the same box can access the websites fine using same proxy. proxy does not require username/password authentication. I do have Crypt::SSLeay installed. #!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->proxy(['https', 'http', 'ftp'], 'http://myproxy.net:8080/'); $ua->agent('Mozilla/5.0'); my $response = $ua->get( 'http://www.yahoo.com' , ':content_file' => "testhttp.html" ); if ($response->is_success) { print "success\n"; } else { print "error\n"; # die $response->status_line; } $response = $ua->get('https://mail.yahoo.com', ':content_file' => 'testhttps.html'); if ($response->is_success) { print "success\n"; #$response->decoded_content; # or whatever } else { print "error\n"; die $response->status_line; }
Re: How to get the multiselect select box or checkbox element values WITHOUT using CGI module
can not say no to you. i am using CGI::Simple now. i will be moving over to mod_perl later. - Original Message - From: Randal L. Schwartz To: Rajeev Prasad Cc: "beginners@perl.org" Sent: Saturday, October 1, 2011 7:06 AM Subject: Re: How to get the multiselect select box or checkbox element values WITHOUT using CGI module >>>>> "Rajeev" == Rajeev Prasad writes: Rajeev> I thought it would be overkill (RAM, CPU etc.) to use CGI.pm Rajeev> when all i need is to get values out of form-variables. but i Rajeev> am going to settle for CGI::Simple CGI.pm is optimized though with it's own version of the lazy loader. If you're already forking for CGI, then the trivial time it takes to load CGI.pm compared to forking shouldn't concern you. If you're looking for performance, you're already using mod_perl, and therefore you're loading CGI.pm once for thousands of hits. Either way, I haven't heard a valid reason from you yet. Just use CGI.pm. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 http://www.stonehenge.com/merlyn/> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.posterous.com/ for Smalltalk discussion -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/