Net::SCP is saving a file name with a wild card

2011-04-28 Thread Dave Thacker
Hi,
I need to pull a file or files down every day that contain a specific
string.   Here's my code.


#!/usr/bin/perl
use strict;
use Net::SCP;

my $scp=' ';
open (LOG, ">>/home/wesaysopost/logs/retrieve-wesayso-results.log") or die
"Can't open logfile";
LOG-> autoflush(1);

print LOG "Starting Retrieval Process";
$scp = Net::SCP->new ( "theserver.wesayso.com", "mylogin");
$scp->cwd("postingscript")  or die "Can't change directories";
$scp->get ("acme_posting*") or die "Can't retrieve results";
close LOG;
exit;

The file I'm retrieving is acme_posting20110415.txt   (date changes every
day)

The file is found, but it's being saved as acme_posting*

I'm not specifying a local file name when I get the file, why is SCP saving
it under a different name?

Thanks in Advance!

Dave


No newlines when writing to a log file

2009-04-30 Thread Dave Thacker
Hi folks,
I've created a log file in my code, and I print various strings to it as I
go through my program.  The problem is that everything is showing up on one
line for each iteration of my main loop, even though I have newlines in the
string.

I'm getting:
The log starts here
Can't make test-sendCan't change to test-send directory.Finished
Transmission at
 s0005rx
Can't make test-sendCan't change to test-send directory.Finished
Transmission at
 s0008rx

What I'm after:
The log starts here
Can't make test-send
Can't change to test-send directory
Finished Transmission at s0005rx
Can't make test-send
Can't change to test-send directory.
Finished Transmission at s0008rx

My code is below.  I'm looking for nifty timestamp idiom too, but I'll
settle for the newlines getting fixed.

TIA
Dave

---begin code--

#!/usr/bin/perl
use strict;
use Net::FTP::File;


open (LOG,">>test-send.log");
print LOG "The log starts here\n";
my $host;

open(HOSTLIST, "hostlist.txt");
while ()   {
$host = $_;
chomp($host);
print "Contacting $host\n";

my $ftp=Net::FTP->new($host,Debug=>0, Timeout=>360) or print LOG "Can't
conn
ect to $host";
$ftp->login("mylogin", "mypasswd") or die "Can't login to $host";
$ftp->binary;


$ftp->cwd("/tmp") or print LOG "Can't change to /tmp";
$ftp->mkdir("test-send") or print LOG "Can't make test-send";
$ftp->cwd("/usr/meh/test-send") or print LOG "Can't change to test-send
d
irectory.";

##put the files in /tmp/test-send
$ftp->put("PRGUPDT.707.2C") or die "unable to send PRGUPDT";
$ftp->chmod("755", "PRGUPDT.707.2C") or die "unable to chmod";

$ftp->quit;
print LOG "Finished Transmission at $host\n";

}

close(LOG);
c


Re: Only getting format header on first file of a series

2008-09-03 Thread Dave Thacker
On Tuesday 02 September 2008 09:15:59 Rob Dixon wrote:
> Dave Thacker wrote:
> > On Monday 01 September 2008 20:29:27 Rob Dixon wrote:
> >>  $- = 0;
> >
> > Unfortunately, there's no change after inserting that assignment.  
> > Thanks for the other info on the improving the preparation of the SQL
> > statement.  I'll do that as soon as I get this resolved.  Any other ways
> > to attack this?
>
> My apologies. That line alone would set the property on STDOUT, not the RF
> file handle as require. Add
>
>   use IO::Handle
>
> at the top of your program, and then use
>
>   open RF, '>', $roster_file or die "Can't open roster file $roster_file";
>   RF->format_lines_left(0);
>
> and I think it should work.

Unfortunately, I seem to have hit another error.  

[EMAIL PROTECTED]:~/efl/dev/efl$ ./roster-report.pl
Unrecognized character \xC2 at ./roster-report.pl line 56.

After staring at perldoc IO::Handle for some time, I made this attempt:

format RF =
@<<<<<<<<<<<  @< @<< @< @< @< @< @<
$name, $age, $nat, $st, $tk, $ps, $sh, $agg
.

format RF_TOP =
Name Age Nat St Tk Ps Sh Ag KAb TAb PAb SAb Gam Sav Ktk Kps Sht Gls 
Ass  DP Inj Sus
---
.

my $io = new IO::Handle;
$io->fdopen(fileno(RF),"w");
    $io->format_lines_left(0);

while ( ($name, $age, $nat, $st, $tk, $ps, $sh, $agg  ) = 
$sth->fetchrow_array() ) {
write $io;
}

#close RF;
undef $io;

But I still get the "Unrecognized character" error at the $io-> format lines 
left statement.   I've definitely wandered off the edge of my map.  Anyone 
got a lifeline?

TIA   Dave


>
> HTH,
>
> Rob



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Only getting format header on first file of a series

2008-09-01 Thread Dave Thacker
On Monday 01 September 2008 20:29:27 Rob Dixon wrote:
>  $- = 0;

Unfortunately, there's no change after inserting that assignment.   Thanks for 
the other info on the improving the preparation of the SQL statement.  I'll 
do that as soon as I get this resolved.  Any other ways to attack this?

TIA, Dave


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Only getting format header on first file of a series

2008-09-01 Thread Dave Thacker
Thanks for the help you folks gave me on my format problems earlier.  I've 
resolved those problems and moved to another!   My program is supposed to 
create a series of roster files.  It creates the files, but only the first 
file gets the header I defined in RF_TOP.   What do I need to change?

TIA  DT

#!/usr/bin/perl

use strict;
use warnings;

use DBI;
use Getopt::Long;
our ($opt_league, $opt_div);


&GetOptions("league=s", "div=s");

print "Working on the $opt_league league, division $opt_div\n";

#connect to database
my $dbh = DBI->connect("DBI:mysql:database=efl",
  'user',
  'password'
  ) or die "Can't connect to database";

#set the root directory of the installation
my $rootdir= "/home/dthacker/efl/dev/";


#open teams.dir for reading
open( CLUB, "<$rootdir/teams.dir"  ) or die "Can't open teams.dir : $!";
while () {
print $_;
my $roster_file=$_;
my $club = substr($_, 0,3);
my $strsql = execute() or die "Couldn't execute statement: $DBI::errstr; 
stopped";

my ($name, $age, $nat, $st, $tk, $ps, $sh, $agg);

format RF =
@<<<  @< @<< @< @< @< @< @<
$name, $age, $nat, $st, $tk, $ps, $sh, $agg
.

format RF_TOP =
Name Age Nat St Tk Ps Sh Ag KAb TAb PAb SAb Gam Sav Ktk Kps Sht Gls 
Ass  DP Inj Sus
---
.

open (RF, ">$roster_file") or die "Can't open roster file $roster_file";

while ( ($name, $age, $nat, $st, $tk, $ps, $sh, $agg  ) = 
$sth->fetchrow_array() ) {
write RF;
}

close RF;

}
$dbh->disconnect();

-format of teams.dir
acm.txt
bar.txt
cel.txt
dep.txt
int.txt
lyo.txt
por.txt
ran.txt
rea.txt
val.txt


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Missing Termination in FORMAT

2008-09-01 Thread Dave Thacker
I'm reading from a database and attempting to write out to several different 
files using a defined format.   I'm using this tutorial on formats as a 
reference.   http://www.webreference.com/programming/perl/format/2.html

When I run the script below, I get the error:
Can't find string terminator "" anywhere before EOF at ./roster-report.pl line 
54.

I *think* I've get everything set up properly, and I'm not sure what I'm 
missing.  The script is below.   Please give me a pointer to the error.

TIA  Dave

#!/usr/bin/perl

use strict;

use DBI;
use Getopt::Long;
our ($opt_league, $opt_div);


&GetOptions("league=s", "div=s");

print "Working on the $opt_league league, division $opt_div\n";

#connect to database
my $dbh = DBI->connect("DBI:mysql:database=efl",
  'user',
  'password',
  ) or die "Can't connect to database";

#set the root directory of the installation
my $rootdir= "/home/dthacker/efl/dev/";


#open teams.dir for reading
open( CLUB, "<$rootdir/teams.dir"  ) or die "Can't open teams.dir : $!";
while () {
print $_;
my $roster_file=$_;
my $club = substr($_, 0,3);
my $strsql = execute() or die "Couldn't execute statement: $DBI::errstr; 
stopped";

my ($name, $age, $nat, $st, $tk, $ps, $sh, $agg, $kab, $tab, $pab, $sab);
FORMAT RF =
  <<  << <<< << << << << << << <<< <<< <<< <<<
  $name, $age, $nat, $st, $tk, $ps, $sh, $agg, $kab, $tab, $pab, $sab
.

open (RF, ">$roster_file");

while ( my ($name, $age, $nat, $st, $tk, $ps, $sh, $agg, $kab, $tab, $pab, 
$sab) = $sth->fetchrow_array() ) {
write RF;
}

close RF;

}
$dbh->disconnect();
close CLUB;


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




print a line of repeating chars to a file

2008-08-31 Thread Dave Thacker
I want to print a line of 50 "-"'s to a file.  This is my non-working syntax.

#!/usr/bin/perl

open (FOO, "foo.out");
print FOO repeat(50,"-");
close FOO;

Undefined subroutine &main::repeat called at ./foo.pl line 4.

Whats the correct syntax for doing this?
TIA, Dave

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Skipping blank lines while reading a flat file.

2005-10-07 Thread Dave Thacker
Perl 5.6  on linux

Given this test file.
--start-
this

is

my file
end--
I want to skip the blank lines and just print the lines with text, like this
this
is 
myfile

This is my test case code. 
#!/usr/bin/perl -w
use strict;

my $opt_testfile="test-text.txt";
open (TS, $opt_testfile) or die "can't open file";
while () {
chomp;
next if ($_ =~ /^\s+/);
print "$_\n";
}

I'm not skipping the lines.  My regex must be wrong.   Can someone show me my 
error please?

TIA
DT

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Retrieving Values from a HOA

2005-09-22 Thread Dave Thacker
Hello perlfolk.
Goal: Create a hash of arrays where 
 hash key = match number
 array[0] = home team
 array[1] = away team
and then retrieve the teams by retrieving all the keys

 while ( @fixture_rec = $sth->fetchrow_array ) {
my $game_id = $fixture_rec[0];
print "0=$fixture_rec[0] 1=$fixture_rec[1] 2=$fixture_rec[2]\n";
my @teams = @fixture_rec[1..2];
print "home=$teams[0] away=$teams[1]\n";
#stuff the hash
$fixture{$game_id} = [ @teams ];
}

return;
}

sub get_teamsheets {
while (($game_id, @teams) = each %fixture) {
print "Game=$game_id Home=$teams[0]\n";
}

return;
}

Here's what my print statements show when I run this

0=2827 1=mba 2=mbb
home=mba away=mbb
0=2828 1=mbc 2=mbd
home=mbc away=mbd
0=2829 1=mbe 2=mbf
home=mbe away=mbf
0=2830 1=mbg 2=mbh
home=mbg away=mbh
0=2831 1=mbi 2=mbj
home=mbi away=mbj
Game=2828 Home=ARRAY(0x83385e4)
Game=2830 Home=ARRAY(0x8338644)
Game=2829 Home=ARRAY(0x8338614)
Game=2831 Home=ARRAY(0x8338674)
Game=2827 Home=ARRAY(0x833859c)

I'm getting the match id back, but the home team is missing.  I don't see 
anything like this in perldsc, but if I'm over looking it, you can point me 
at it.   I may have gotten this idea from the Camel book, but my copy is at 
work right now.   Please help me to understand what I'm doing wrong.

TIA
Dave

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Perl 5.6.0, AIX, Missing Module

2005-05-30 Thread Dave Thacker
On Monday 30 May 2005 13:16, Craig Moynes wrote:
> I am using the File::Tail perl module.  When I try to run my script I
> get the following error message:
>
> Can't locate loadable object for module Time::HiRes in @INC (@INC
> contains: /usr/opt/perl5/lib/5.6.0/aix /usr/opt/perl5/lib/5.6.0
> /usr/opt/perl5/lib/site_perl/5.6.0/aix
> /usr/opt/perl5/lib/site_perl/5.6.0 /usr/opt/perl5/lib/site_perl .) at
> /usr/opt/perl5/lib/site_perl/5.6.0/File/Tail.pm line 21
> Compilation failed in require at
> /usr/opt/perl5/lib/site_perl/5.6.0/File/Tail.pm line 21.
>
> however Time/HiRes.pm is located in
> /usr/opt/perl5/lib/5.6.0/aix/Time/HiRes.pm, it is accessbile by my
> userid, and running a perldoc -m Time::HiRes does work.
>
> Anyone know of something that could fix this?

Do you have a PERL5LIB environment variable set?  
export PERL5LIB=/usr/opt/perl5/lib/5.6.0/aix

That may do the trick.

Dave

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]