limekiller has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to write a tool that scp mtr to two machines, then ssh to those two machines and run nmap to a third computer. I was thinking:
./checkfilter -ip1 1.2.3.4 -ip2 5.6.7.8 -ip3 2.3.4.5<P>
...but I don't know how to set up command line options in perl. I've searched this site but didn't find anything that explained it. My "learning perl" tome simply refers to "programming perl".

thanks,
limekiller

Replies are listed 'Best First'.
Re: command line options syntax
by $code or die (Deacon) on Feb 21, 2001 at 08:04 UTC
    Hi limekiller,

    You need to look at GetOpt::Long which comes with the standard perl distribution I think.

    It does what you want - handling multiple value command line options with long names. You might want to look at the other assortment of GetOpt::* modules that there are too.

    Update: You might not want to have all three ip adresses under the same commandline-option name, since you are scp-ing to 2 computers and then connecting to the third the GetOpt::*, might not put them in the correct order - but even if it it does, your users might not, you can cut down errors if you have 2 or 3 option names, like:
    checkfilter.pl -machine1 '192.168.0.1' -machine2 '192.168.0.2' -machi +ne3 '192.168.0.3' # or checkfilter.pl -mtr '192.168.0.1' -mtr '192.168.0.2' -nmap '192.168.0 +.3'
    With the second example, you could loop through the -mtr switches, mtr and scp to it, then ssh and nmap to -nmap. This would mean you could add as many "-mtr"s as you want. Does this make sense - I know only a little about mtr and nmap?

    $code or die
    Using perl at
    The Spiders Web
Re: command line options syntax
by archon (Monk) on Feb 21, 2001 at 08:01 UTC
    You want to use the Getopt::Std module that comes with perl. perldoc Getopt::Std for more info.
      GetOpt::Std only allows single-character option names, so "-ip" would be out. Also I think that it doesn't handle multiple values for a switch. This isn't mentioned in GetOpt::Std docs, but it is for GetOpt::Long.

      Maybe GetOpt::Mixed would be a good suggestion - because it combines long and std with some extras.

      Sidenote/Update: BTW, there's also GetOpt::Simple, but it doesn't look very simple!

      $code or die
      Using perl at
      The Spiders Web