First Commercial Perl Program

Discussion in 'C Programming' started by tbb!/fbr!, Mar 10, 2012.

  1. tbb!/fbr!

    tbb!/fbr! Guest

    I entered the professional perl programming world by being paid
    (that's what I call professional, though the code may be far from) for
    a very small perl script. The user basically wanted a config file
    which contained as the first line a username, the second line a
    password, and the remaining lines to be hotnames.

    ex.
    user
    pass
    127.0.0.1
    127.0.0.2

    Then I wrote the following script. It gathers the user, pass, and
    hostlist, and then establishes an ssh connection to query a 'device'
    and return the output in a file named after the host. Following is
    that program:


    #!/usr/bin/perl

    # Code by
    # For
    # dmon-1.6

    use warnings;
    use strict;
    use Net::SSH::perl;

    my $cfgfile="./config";
    open CONFIG, "<", $cfgfile || die $!;
    chomp(my @cfgdat=(<CONFIG>));
    my $user=shift(@cfgdat);
    my $pass=shift(@cfgdat);
    my $extcmd="ls -l";
    my $stime=3;

    while (defined $stime) {
    foreach (@cfgdat) {
    my $ssh=Net::SSH::perl->new($_);
    $ssh->login($user,$pass);
    my ($stdout,$stderr,$exit)=$ssh->cmd($extcmd);
    open OUTFILE, ">>", $_ || die $!;
    if ($stdout) {
    print OUTFILE $stdout;
    }
    if ($stderr) {
    print OUTFILE $stderr;
    }
    close OUTFILE;
    }
    sleep $stime;
    }

    I am just looking for critique. I have been a Unix Admin for over 15
    years, and have used perl for one off scripts, but I spent time and
    master Oreillys Learning Perl and Intermediate Perl (Mastering and
    Advanced Perl are next) and am now looking to solely become a
    commercial perl programmer. However, as I lack commercial experience,
    I probably lack a 'standard' way of approaching things, or at least
    don't know what experienced perl programmers know, which I'll learn as
    a function of time. Either way, if you have time, let me know how I
    could have done all this better, and maybe even a source of commercial
    perl programs I can look at and see how pro's do it.

    Ron
    tbb!/fbr!, Mar 10, 2012
    #1
    1. Advertising

  2. tbb!/fbr!

    tbb!/fbr! Guest

    On Mar 10, 11:03 am, "tbb!/fbr!" <> wrote:
    > I entered the professional perl programming world by being paid
    > (that's what I call professional, though the code may be far from) for
    > a very small perl script. The user basically wanted a config file
    > which contained as the first line a username, the second line a
    > password, and the remaining lines to be hotnames.
    >
    > ex.
    > user
    > pass
    > 127.0.0.1
    > 127.0.0.2
    >
    > Then I wrote the following script. It gathers the user, pass, and
    > hostlist, and then establishes an ssh connection to query a 'device'
    > and return the output in a file named after the host. Following is
    > that program:
    >
    > #!/usr/bin/perl
    >
    > # Code by
    > # For
    > # dmon-1.6
    >
    > use warnings;
    > use strict;
    > use Net::SSH::perl;
    >
    > my $cfgfile="./config";
    > open CONFIG, "<", $cfgfile || die $!;
    > chomp(my @cfgdat=(<CONFIG>));
    > my $user=shift(@cfgdat);
    > my $pass=shift(@cfgdat);
    > my $extcmd="ls -l";
    > my $stime=3;
    >
    > while (defined $stime) {
    >   foreach (@cfgdat) {
    >     my $ssh=Net::SSH::perl->new($_);
    >     $ssh->login($user,$pass);
    >     my ($stdout,$stderr,$exit)=$ssh->cmd($extcmd);
    >     open OUTFILE, ">>", $_ || die $!;
    >     if ($stdout) {
    >       print OUTFILE $stdout;
    >     }
    >     if ($stderr) {
    >       print OUTFILE $stderr;
    >     }
    >     close OUTFILE;
    >   }
    >   sleep $stime;
    >
    > }
    >
    > I am just looking for critique. I have been a Unix Admin for over 15
    > years, and have used perl for one off scripts, but I spent time and
    > master Oreillys Learning Perl and Intermediate Perl (Mastering and
    > Advanced Perl are next) and am now looking to solely become a
    > commercial perl programmer. However, as I lack commercial experience,
    > I probably lack a 'standard' way of approaching things, or at least
    > don't know what experienced perl programmers know, which I'll learn as
    > a function of time. Either way, if you have time, let me know how I
    > could have done all this better, and maybe even a source of commercial
    > perl programs I can look at and see how pro's do it.
    >
    > Ron


    shit, wrong newsgroup...

    Ron
    tbb!/fbr!, Mar 10, 2012
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Korto
    Replies:
    29
    Views:
    1,057
    Chris Uppal
    Nov 15, 2006
  2. Christopher M. Lusardi
    Replies:
    3
    Views:
    189
    Alan J. Flavell
    Oct 19, 2003
  3. Patrick Finnegan

    Using embedded PERL with commercial applications?

    Patrick Finnegan, Nov 24, 2004, in forum: Perl Misc
    Replies:
    13
    Views:
    297
    Tad McClellan
    Nov 26, 2004
  4. PerlFAQ Server
    Replies:
    0
    Views:
    175
    PerlFAQ Server
    Apr 23, 2011
  5. tbb!/fbr!

    First Commercial Perl Program

    tbb!/fbr!, Mar 10, 2012, in forum: Perl Misc
    Replies:
    30
    Views:
    1,067
    tbb!/fbr!
    May 20, 2012
Loading...

Share This Page