Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Seekers of Perl Wisdom

( #479=superdoc: print w/ replies, xml ) Need Help??

If you have a question on how to do something in Perl, or you need a Perl solution to an actual real-life problem, or you're unsure why something you've tried just isn't working... then this section is the place to ask. Post a new question!

However, you might consider asking in the chatterbox first (if you're a registered user). The response time tends to be quicker, and if it turns out that the problem/solutions are too much for the cb to handle, the kind monks will be sure to direct you here.

User Questions
Unable to establish SMB2 connection using Filesys::SmbClient
No replies — Read more | Post response
by Netras
on Feb 09, 2016 at 08:05

    Hello Perl Monks,

    I need to access a SMB host which requires SMB version 2. Filesys::SmbClient (3.2) has served me well working with SMB1 but does not successfully create a SMB2 connection. This is the error I get:

    samba_tevent: EPOLL_CTL_DEL EBADF for fde[0x27c9930] mpx_fde[(nil)] fd[8] - disabling

    Directly using smbclient with SMB version 2 works fine:

    smbclient -U domain\\user //HOSTNAME/ShareName -c "dir" -m SMB2

    But when omitting the max-protocol tag (-m) while using smbclient, a very similar error appears:

    smbclient -U domain\\user //HOSTNAME/ShareName -c "dir" samba_tevent: EPOLL_CTL_DEL EBADF for fde[0x7f454d1eff50] mpx_fde[(nil +)] fd[7] - disabling

    I assume that Filesys::SmbClient is trying to use SMB version 1 to connect to the target host and I have no idea how I can change this behaviour. I have checked the official module documentation with no success and tried forcing the client protocol version in /etc/samba/smb.conf but this has no effect on Filesys::SmbClient as well.

    Is there someone that has had this issue or has any ideas? I would appreciate any feedback and/or help in the matter.

    Thank you!

socket checker in multiple hosts for multiple destination
No replies — Read more | Post response
by Bams
on Feb 09, 2016 at 06:45

    Hi, I am trying to write a program in perl. it is to check socket from my local machine to multiple remote machines, to multiple destinations. The limitation i have is, on my local machine i only have standard modules installed. I am using expect to skip password as well 1. source hosts list abc.com def.com ghi.com 2. destination list contains host and port as a cvs file 123.com,1586 456.com,1234 789.com,5678 these files should be passed as argument , my program is still incomplete without expect. any help would be greatly appreciated

    #!/usr/bin/perl -w use Data::Dumper; use Expect; use strict; use warnings; my $exp = new Expect; $exp->log_file("SSHLOGFILE.txt"); $exp->log_stdout(0); my $user = 'xxxxxx'; my $pw = 'yyyyyyyy'; if( ! defined $ARGV[0] ) { print "Usage: new.pl source destination\n"; exit; } my $file1 = $ARGV[0] or die "Need to get CSV file on the command line\ +n"; my $file2 = $ARGV[1] or die "Need to get CSV file on the command line\ +n"; open my $info, $file1 or die "Could not open $file1: $!"; while( my $line = <$info>) { print $line; open(SSH,"/usr/bin/ssh xxxxxx\@host ps aux |") or die "$!\n"; open my $data, $file2 or die "Could not open $file2: $!"; for (my $nice = <$data>) { chomp ($nice); my ($servername, $portnumber) = split (',', $nice); print "$servername \n"; print "$portnumber \n"; while (<SSH>) { printf "%s %s\n", $servername, $portnumber; use IO::Socket; my $sock = new IO::Socket::INET (PeerAddr => $servername,P +eerPort => $portnumber,Proto => 'tcp'); print "ERROR: Could not create socket: $!\n" unless $sock +; printf "%s\n", "SUCCESS: Port Responded" if $sock; close($sock) if $sock; } close SSH; exit; redo; } close $data; } close $info; exit
HTML::Template duplication of tags
1 direct reply — Read more / Contribute
by Anonymous Monk
on Feb 09, 2016 at 02:44

    Is it permitted to use a <TMPL_VAR NAME=XX> tag more than once in an HTML doc? I could assign the same value to two different tags but that feels a bit clunky!

Can't call method "proxy" on an undefined value at
1 direct reply — Read more / Contribute
by Anonymous Monk
on Feb 08, 2016 at 23:08

    I know I'm missing something but I can't see why I'm getting the error, Can't call method "proxy" on an undefined value at. Here's my code

    open(my $fh, '<', 'cities.txt') or die $!; print $fh; open(my $prx, '<', 'proxies.txt') or die $!; print $prx; mkdir 'Bing', 0755; mkdir 'Bing/1Parsed/', 0755; mkdir 'Bing/1Parsed/Html/', 0755; chomp(my @cities = <$fh>); close($fh); chomp(my @prx = <$prx>); close($prx); open($fh, '<', 'keywords.txt') or die $!; for my $city (@cities) { seek($fh, 0, 0); while (my $keywords = <$fh>) { chomp($keywords); print "$city $keywords\n"; my $xml1 = $link1 . $city ."+". $keywords . $link2 . $city ."+". $ +keywords . $link3; #my $xmla = $link3 . $row . ".com"; #my $xmlx = $link4 . $row; my $filename1 = "Bing/".($city)."_". ($keywords) . ".html"; open my $fh1, ">", $filename1 or die("Could not open file. $!"); #toggle proxy selection my $prx=$_; my $ua->proxy('http', $prx); $ua->agent('Mozilla/8.0'); print "using:"; print "proxy"; print $prx;

    The above is a piece of a sub script in a bigger script. Any guidance is greatly appreciated

Howto Threads
2 direct replies — Read more / Contribute
by sunder
on Feb 08, 2016 at 22:28
    So i am an Engineer for a ISP. I have a need to validate Customer Routers are reachable before and after a maintenance by pinging them. The current program that I use doesn't thread to speed things up so it can take a long time to complete.

    Here is the overview what i am trying to do.

    Give the program a list of ip's to ping in a list\array.
    Thread to create a process for each ping task.
    Then when the ping task completes return the outcome (Latency or Unreachable) back to the original process and put it in to array
    Then print the results.

    I have never done any programming with threads or forking.

    First off is threads the correct way to program this?

    Second does someone know of a good tutorial or have a good example?

    Thanks in advance
Inline C solaris vs linux
2 direct replies — Read more / Contribute
by ccgcube
on Feb 08, 2016 at 17:07

    Hi All,

    I'm working on a set of tools that must run on both solaris and linux. I've written a set of packages using Inline::C, primarily to manipulate large arrays. The code compiles and runs correctly on linux.

    It compiles and runs on solaris too, but I'm not getting the results I'm looking for.

    The code below is the smallest version of the code I can come up with to demonstrate the problem. The newthing() function is intended to return a pointer to a blessed object, in this case our small struct Thing. In the interest of full disclosure, newthing() was stolen almost verbatim from Inline::C-Cookbook (thanks!).

    That reference may be used from the perl side to call $thingref->bump() from the perl side. The bump function should increment thing->index, and assign the simtime parameter to thing->simtime.

    The problem is that the solaris version does not increment the index, and does not appear to handle the simtime parameter correctly. Both values stay at zero when they should be non-zero (recall that this runs correctly on linux). A sample of the output follows the code.

    My first quess was that I've got a type mismatch somewhere. Changing the type of the obj parameter to bump() from SV * to UV * or IV * compiles, but produces this message at runtime:

    Can't locate object method "bump" via package "Short" at ./p_passi +ng_blessed line 58.

    ... and I am obviously guessing.

    The version of perl on both systems is 5.18.4.

    perl -V on solaris returns this (among other things):

    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=87654321 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=1 +6 ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='of +f_t', lseeksize=8

    I suspect that somewhere along the line, my object has been misallocated, and it is the difference between ivsize and ptrsize that is the source of the issue... but again, I'm guessing.

    package Short; use Inline C; use strict; # no strict 'refs'; 1; ## # __DATA__ __C__ #ifndef Newx # define Newx(v,n,t) New(0,v,n,t) #endif typedef struct { UV index; UV simtime; } Thing; // -------------------------------------------------------- // shamelessly stolen from Inline::C-Cookbook // SV* newthing( const char * classname ) { Thing * thing; SV * obj; SV * obj_ref; Newx( thing, 1, Thing ); thing->index = 0; thing->simtime = 0; obj = newSViv( (IV)thing ); obj_ref = newRV_noinc(obj); sv_bless( obj_ref, gv_stashpv( classname, GV_ADD ) ); SvREADONLY_on( obj ); return obj_ref; } // -------------------------------------------------------- // void DESTROY(SV* obj) { Thing* thing = (Thing*)SvIV(SvRV(obj)); printf("FREE thing size : %d\n", sizeof( thing ) ); Safefree( thing ); } // -------------------------------------------------------- // void bump( SV* obj, UV simtime ) { Thing* thing = (Thing*)SvIV(SvRV(obj)); printf("obj size : %lu\n", sizeof( obj ) ); printf("obj val : %lx\n", (unsigned long)obj ); printf("thing size : %d\n", sizeof( thing ) ); printf("thing val : %lu\n", (unsigned long)thing ); printf("thing simtime p : %lu\n", simtime ); printf("thing simtime A : %lu\n", thing->simtime ); printf("thing index A : %lu\n", thing->index ); thing->simtime = simtime; thing->index += 1; printf("thing simtime B : %lu\n", thing->simtime ); printf("thing index B : %lu\n", thing->index ); }

    Sample Output

    # --------------------- Devel::Peek::Dump output so we can compare values: SV = IV(0x2bf2d8) at 0x2bf2d8 REFCNT = 1 FLAGS = (PADMY,ROK) RV = 0x2216b0 SV = PVMG(0x4372c8) at 0x2216b0 REFCNT = 1 FLAGS = (OBJECT,IOK,READONLY,pIOK) IV = 7888424 NV = 0 PV = 0 STASH = 0x30a5e8 "Short" # --------------------- perl passing simtime: 20 obj size : 4 obj val : 2bf2d8 thing size : 4 thing val : 7888424 thing simtime p : 0 << should be 20 thing simtime A : 0 thing index A : 0 thing simtime B : 0 << should be 20 thing index B : 0 << should be 1 perl passing simtime: 40 obj size : 4 obj val : 2bf2d8 thing size : 4 thing val : 7888424 thing simtime p : 0 << should be 40 thing simtime A : 0 thing index A : 0 thing simtime B : 0 << should be 40 thing index B : 0 << should be 2 FREE thing size : 4

    Thanks in advance,

Preferred authentication in Net::SFTP::Foreign
2 direct replies — Read more / Contribute
by mithunbh
on Feb 08, 2016 at 16:43
    So we have a huge setup of SFTP connections and their configurations and now we are encountering situations where we have to tune the Preferred Authentication. Since the basis of Net::SFTP::Foreign was supposed be to piggy back on the underlying ssh libraries we naively assuming ~/.ssh/config would be fully honored except that the module has chosen to explicitly override Preferred Authentication.

    Does anyone have suggestions what can be done to stop the module from overriding it other than explicitly forking off from the package ?

Do a named regex group in 5.8?
3 direct replies — Read more / Contribute
by crusty_collins
on Feb 08, 2016 at 15:57
    I was wondering if I can do a named group regex with some kind of trickery like is available in 5.10?
    any ideas?


    snippet from http://www.regular-expressions.info/refext.html
    (?<x>abc){3} matches abcabcabc. The group x matches abc.

    "We can't all be happy, we can't all be rich, we can't all be lucky and it would be so much less fun if we were. There must be the dark background to show up the bright colours." Jean Rhys (1890-1979)
To find and count a repeating pattern in a line
2 direct replies — Read more / Contribute
by punitpawar
on Feb 08, 2016 at 14:24
    Hello,
    I wanted to know if there is any way by using regular expression to count the occurrences of a repeating pattern in a line ?
    here is the problem statement
    Given a log file:
    some garbage...from:123.54,78.21...more garbage..to:56,82,124.54...more some more garbage...from:11.54,45.84...garbage..to:115.87,98.65 ... Assumption: these coordinates will always appear in sequence: from ... to... from ... to... But these from - to pair may or may not be on same line
    Write a script to return pairs of (from, to) coordinates.
    The only way I could think of was by splitting the line....But I feel there should be a better way. here is my code below
    #!/usr/bin/perl use Data::Dumper; open(FH,"<abc.txt")or die EXPR; while (<FH>) { my @words = split(/ /,$_); foreach (@words) { if ($_=~/from:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/) { print "$1- \n"; }elsif ($_ =~/to:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/){ print "$1 \n"; } } } close (FH);
    This is the sample input file abc.txt
    hshhhgljlkjglgkjj from:198.18.66.5 aegighighighilg to:198.18.66.6 iiuf +duifuiuih from:198.18.66.7 hiihhj to:198.18.66.8 hhouhoho from:198.18.66.9 igilgojhjh to:198.18.6 +6.10 igighliho from:198.18.66.11 highighioouhouhhhoh to:198.18.66.12
    And the output I am expecting is
    198.18.66.5 ,198.18.66.6 198.18.66.7 ,198.18.66.8 198.18.66.9 ,198.18.66.10 198.18.66.11 ,198.18.66.12
Seek and Find
1 direct reply — Read more / Contribute
by hbrown.bios
on Feb 08, 2016 at 12:06
    Hey guys, I'm still pretty new to perl, so I'm not even sure is this will work, but here is what I am trying to do. I have 2 files. say file A has a list of numbers (which I can put into an array because there aren't very many of them) and I want to search file B which has 7 columns. I want perl to print the matching line to a new file if column 2 matches a value in file a (or the array) AND matches a search phrase in column 7 and if the value in column 4 falls into a specified range. Any and all help would be greatly appreciated!

Add your question
Title:
Your question:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":


  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (9)
    As of 2016-02-09 14:23 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?





      Results (316 votes), past polls