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

I am working on a script that goes out to a host and grabs the .lic files for Veritas so we can keep a record of the keys. Any suggestions on how to make this smoother? Seems it should be simpler than this?
#!/usr/bin/perl -w use Net::FTP; $LIC_DIR = "/home/user/admin/keys"; @files = grep(/\.lic$/, readdir(LDIR)); $ftp = Net::FTP->new("ip address") or die "can't + connect: $@\n"; $ftp->login("user", "password") or die "could +n't login\n"; $ftp->cwd("/etc/vx/elm") or die "could +n't change directory\n"; $ftp->binary(); $ftp->quot("prompt"); foreach $x ( @files ) { $x =~ s/.lic/; print "Getting file $x\n"; $ftp->get($x) or die "could +n't get $x: $@\n"; } $ftp->quit; # outta here

Replies are listed 'Best First'.
Re: grabbing .lic files
by vek (Prior) on Mar 28, 2003 at 01:22 UTC
    This line probably causes you some grief:
    $x =~ s/.lic/;
    You'll probably get a Substitution not terminated at... error I would imagine. You probably meant to do this:
    $x =~ s/.lic//;
    -- vek --
Re: grabbing .lic files
by grantm (Parson) on Mar 28, 2003 at 00:08 UTC

    I would just use SCP.

      How? SCP doesn't provide a way to get directory listings, and (IIRC) doesn't do filename globbing. I can see this being done with SFTP, but not SCP.

      Update: Never mind. I am an idiot.

      I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
      -- Schemer

      Note: All code is untested, unless otherwise stated

        This type of thing is perfect for scp. Especially if you have keys between trusted hosts so that you do not need to enter a password (or put it in a file in the clear):

        for host in host1 host2 host3 host4 do scp $host:/etc/vx/elm/*.lic /home/user/admin/keys done

        scp most certainly supports globbing. It can also recursively copy a directory and keep the same ownership/file permissions of files and a bunch of other great things.

        The other alternative is to set up a generic Perl script that you can pass command line parameters to:

      • Local directory
      • Remote directory
      • File list
      • Username/Password
      • etc

        To me, it seems easier to have the key authentication set up with scp so that I can do this on the command line on the fly. There are times when I can't because the host is not local or trusted, and have set up a script that is maleable enough that I do not have to edit it before each use.

        Cheers - L~R

        Which is irrelevant, as this script gets a listing of the files locally, and then retrieves those same filenames from the remote machine, there isn't any directory listing or filename globbing being done via ftp anyway.

        We're not surrounded, we're in a target-rich environment!

        scp does glob files or rather the shell on the other end globs files. You need to escape the meta characters from your local shell of course.

        scp\*.lic .
Re: grabbing .lic files
by krujos (Curate) on Mar 28, 2003 at 16:33 UTC
    Why not just rcp the lic files over. You could also consider logging on to the machine remotely and run the license utility that way.
    Example if your running NetBackup (Which I think is where the elm/*.lic files come from). $lics = `rsh $machine "/usr../admincmd/bpminlicense"`

      And if the OP wanted to copy files between two interconnected hosts without a connection to any other machine, not even a coffee-maker:
      do not suggest the usage of rsh, rcp, remote-without-encrypted-ssl-or-ssh-tool-of-your-choice to anybody, because if they get used to these, they may use them without thinking in circumstances where they don't want to.

      Use ssh, scp, rsync -e ssh, CVS_RSH=ssh, ...for whatever intermachine communication involving authentication you have, just to get used to it and do it automatically when it's important.

      I know this is kind of over-zealous, but it's like driving drunk: I don't care about the mischief of a drunken driver (as long as we're not befriended :-), but I care for the poeple dying in an accident because of the driver being drunk.
      I don't care for machines taken over because there admins not performing well enough to protect there machines reasonably, but the machines DoSed from this machine (and a lot of others) could be mine, and I don't like that!

      I hope I could make my point without turning into a complete a#@hole; just remember that I'm not a native english-speaker, and to use encrypted connections!


        At the risk of starting some larger than life discussion.
        Yes you have a point, unsecured methods are not the greatest thing in the world. On the other hand, in largeish data center places or cooperate computing environments (i.e. places where your likely to find Veritas software) most of those (ssh, scp etc.. ) utilities are not installed on the boxes. Remember, the tools you mention are not always installed by default (Sun just added those tools to the default Solaris 9 install, and a quick check on other vendors (AIX 5.2, HP-UX 11.11) reveals they are missing). (Yes yes, every sysadmin should install them etc, but lets be honest, it just doesn’t happen...). As the poster stated he is getting license keys off his machines. I have my doubts that his machines are hanging out in a wide open / unsecured environment when he is using Net::FTP as a possible solution to his problem. rcp / rsh is a reasonable solution for this problem.
        update. Fixed formatting.