Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   First Commercial Perl Program (http://www.velocityreviews.com/forums/t869240-first-commercial-perl-program.html)

tbb!/fbr! 03-10-2012 07:03 PM

First Commercial Perl Program
 
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! 03-10-2012 07:16 PM

Re: First Commercial Perl Program
 
On Mar 10, 11:03*am, "tbb!/fbr!" <ronaldljohn...@gmail.com> 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


****, wrong newsgroup...

Ron


All times are GMT. The time now is 08:09 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.