possible link/ARGV problem?

C

courtney.machi

Hello,

I am writing 2 scripts - s2 parses logfiles located in a different
directory, s1 calls s2 and provides the path to the logfiles. When i
run s1, it appears to be reading the logfile but not writing anything.
when i run s2 (although not necessary) it says 'can't open logfile: no
such file or directory'. I am assigning the $host = ARGV[0] and
$logfile = ARGV[1] in s2, then in s1 looping through each logfile and
calling s2 to parse and write. Hopefully this is not too ambiguous -
does anyone have any suggestions??

Thanks,
Courtney
 
C

courtney.machi

by the way, here is a snippet of code:

$host = $ARGV[0];
$logfile = $ARGV[1];

# Initialize record counters.
$n_read = $n_written = 0;
$n_other_user = $n_other_time = $n_stdin_acctcom = 0;

$last_entry = '';

# Parse the log file.

open(IN,"<$logfile") || die "can't open log file $logfile: $!\n"; <---
at this line i am getting this error: Use of uninitialized value in
concatenation (.) or string
??
 
P

Paul Lalli

I am writing 2 scripts - s2 parses logfiles located in a different
directory, s1 calls s2 and provides the path to the logfiles. When i
run s1, it appears to be reading the logfile but not writing anything.
when i run s2 (although not necessary) it says 'can't open logfile: no
such file or directory'. I am assigning the $host = ARGV[0] and

What language is that? In Perl, the arguments are kept in @ARGV, so
you'd access the first one with

$host = $ARGV[0];
$logfile = ARGV[1] in s2, then in s1 looping through each logfile and
calling s2 to parse and write. Hopefully this is not too ambiguous -
does anyone have any suggestions??

Suggestions:
* minimize your scripts to the shortest possible example that still
demonstrates your error.
* Make sure you're using strict and warnings
* print the filename you're attempting to open in the error output.
Rather than `die "Cannot open logfile: $!"`, make it `die "Cannot open
logfile '$logfile': $!"`
* if the above three suggestions don't help you find your answer,
provide us with the minimized scripts - in a form we can run by copy
and pasting.

Paul Lalli
 
J

Joe Smith

by the way, here is a snippet of code:

Your snippet did not show the script verifying its arguments.
$host = $ARGV[0];
$logfile = $ARGV[1];

my $Usage = "Usage: $0 host logfile\n";
my $host = $ARGV[0] or die "Host name missing\n",$Usage;
my $logfile = $ARGV[1] or die "Log file name missing\n",$Usage;
open(IN,"<$logfile") || die "can't open log file $logfile: $!\n";

open my $in,'<',$logfile or die "Can't open log file $logfile: $!\n";
at this line i am getting this error: Use of uninitialized value in
concatenation (.) or string

So, how exactly are you invoking your second script?
Anything like this:
system('s2.pl',$host,$logfile) == 0 or die "Failed: s2.pl $?";
or
$result = `./s2.pl $host $logfile`
die "No results from s2: $?\n" if $? or $result eq "";

-Joe
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top