CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
spread sheet output

 



surjithss
Novice

Mar 5, 2008, 7:10 AM

Post #1 of 6 (677 views)
spread sheet output Can't Post

Hi,

I am trying to get the filesystem details of a unix server.But I am getting some errors.It has been mentioned below the code.Apart from this I need to get this output to a spreadsheet.Anybody can help me out?

#!/usr/local/bin/perl
use strict;
unless(open(INFILE,">>file1")){
die("can not\n");
}
unless(open(OUTFILE,">>file2")){
die("can not\n");
}
my @df=`df -k|awk {'print \$6'}`;
print INFILE (@df);
my @detail=<INFILE>;
my $line;
foreach $line (@detail)
{
my @final=`cd $line|ls -lrt`;
print OUTFILE ("For filesystem:\n");
print OUTFILE ($line);
print OUTFILE (@final);
}
print ("You have finished your job\n");

Error::

sh: syntax error at line 1: `(' unexpected
sh: syntax error at line 1: `(' unexpected
sh: }: does not exist
sh: syntax error at line 1: `(' unexpected
sh: syntax error at line 2: `|' unexpected
sh: syntax error at line 2: `|' unexpected


KevinR
Veteran


Mar 5, 2008, 12:21 PM

Post #2 of 6 (675 views)
Re: [surjithss] spread sheet output [In reply to] Can't Post

the errors appear to be coming from the shell (sh). But here you are trying to read from INFILE:

print INFILE (@df);
my @detail=<INFILE>; <------ here

but you never opened INFILE for reading, only writing. Maybe you could do this:


Code
#!/usr/local/bin/perl 
use strict;
open(OUTFILE,">>file2") or die "can not: $!\n";
my @detail = `df -k|awk {'print \$6'}`;
foreach my $line (@detail){
my @final = `cd $line|ls -lrt`;
print OUTFILE "For filesystem:\n";
print OUTFILE $line;
print OUTFILE @final;
}
close OUTFILE;
print "You have finished your job\n";



I can't help with the spreadsheet part of your question.
-------------------------------------------------


surjithss
Novice

Mar 6, 2008, 6:13 AM

Post #3 of 6 (665 views)
Re: [KevinR] spread sheet output [In reply to] Can't Post

Hi Kevin,

Thanks for your help,But I got some syntax error when I tried the code.I think, in line 6 after `cd $line the piping command(|) is not taking.It is thowing some syntax error.Can you please tell me,how can I give a variable name inside a unix piped command.

Thanks


KevinR
Veteran


Mar 6, 2008, 8:57 AM

Post #4 of 6 (661 views)
Re: [surjithss] spread sheet output [In reply to] Can't Post

A perl syntax error? You should post the error you are getting. To me it looks like it should work OK. What are the values of @detail array?
-------------------------------------------------


surjithss
Novice

Mar 10, 2008, 6:28 AM

Post #5 of 6 (651 views)
Re: [KevinR] spread sheet output [In reply to] Can't Post

Hi Kevin,

Sorry for the delay in reply.The error which I got while running the code is

sh: Mounted: does not exist
sh: syntax error at line 2: `|' unexpected
sh: syntax error at line 2: `|' unexpected
sh: syntax error at line 2: `|' unexpected
sh: syntax error at line 2: `|' unexpected
sh: syntax error at line 2: `|' unexpected
sh: syntax error at line 2: `|' unexpected.

And array @detail contains the filesystem names.I think, the error occurs, while giving the scalar variable $line inside a command.

Thanks


(This post was edited by surjithss on Mar 10, 2008, 6:32 AM)


KevinR
Veteran


Mar 10, 2008, 11:11 AM

Post #6 of 6 (645 views)
Re: [surjithss] spread sheet output [In reply to] Can't Post

The error appears to be coming from the shell. Print these lines and see what the shell is recieving from the perl script:


Code
foreach my $line (@detail){  
print qq{"cd $line|ls -lrt"\n};
#my @final = `cd $line|ls -lrt`;
#print OUTFILE "For filesystem:\n";
#print OUTFILE $line;
#print OUTFILE @final;
}


it might help you find out what is causing the shell to error out.
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives