hello world,
how can edit this script to read $server from file An example is inside the file :- 192.168.1.1 192.168.1.2 192.168.1.3 192.168.1.4 192.168.1.5 ================== line 8 my $server = $ARGV[0];
#!/usr/bin/perl use IO::Socket; use Net::hostent; use Getopt::Std; my $server = $ARGV[0]; my $fileconfig="config-file"; my $max_processes = 10; print "TFTP file word database: $fileconfig \n"; print "TFTP server $server \n"; print "Max processes $max_processes \n"; $timeout = 2; $port = 69; $retries=2; my @pids; my $npids=0; open( fileconfig, "<$fileconfig") || die " Cannot open the word fil +e : $fileconfig ! \n"; chomp(@fileconfig = <fileconfig>); close(fileconfig); foreach $file (@fileconfig) { my $pid; $pid=fork(); if($pid>0){ $npids++; print " Processes are: $npids\n" ; if($npids>=$max_processes){ for(1..($max_processes)){ my $wait_ret=wait(); if($wait_ret>0){ $npids--; } } } next; }elsif(undef $pid){ print " Fork error!\n"; exit(0); }else{ local $SIG{'ALRM'} = sub { exit(0); }; alarm 0; eval { tftp_check($file); }; exit(0); } } for(1..$npids){ my $wt=wait(); if($wt==-1){ print " is $!\n"; redo; } } sub tftp_check { my $file =shift; my $MAXLEN=2; my $op=01; my $mode = "netascii"; my $count=$retries; my $pkt = pack("n a* c a* c", $op, $file, 0, $mode, 0); if ( $count != 0 && $treturn !="03") { my $sock = IO::Socket::INET->new(Proto => 'udp'); send($sock,$pkt,0,pack_sockaddr_in($port,inet_aton($serve +r))); undef($treturn); undef($rpkt); eval { local $SIG{ALRM} = \&timed_out; alarm $timeout; $sock->recv($rpkt, $MAXLEN); close $sock; alarm 0; } ; $count--; @rets = split( //, $rpkt ); foreach $currentret (@rets) { $treturn .= ord($currentret); } if ($treturn =="03") { print "*** Found TFTP server remote filename : $file \n"; return 1; } } $count=$retries; }

In reply to script read from file by alaa21a

Title:
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, details, 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, summary, 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.