Perl printing error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl printing error
# 1  
Old 02-11-2009
Perl printing error

Hi Scripting Gurus, I am new bee in perl, and trying to write a script which must print the free disk space availability of C and E drives. Please advice.

Here is the script snippet and expected output:


#!/usr/bin/perl
use CGI qw/:html3 :standard/;
$spaceuselog = "E:\\admin\\VOBSpaceUsage\\vobspaceusage.log.txt";
$report = "E:\\admin\\VOBSpaceUsage\\vobspaceusage.html";
open(LOG, ">$report") || die "ERROR writing to logfile $logfile!";
$datetime=localtime();
$count=0;
$vob="";
$vobsize=0;
$totalvobsize+=0;
$vd="";
$sum=0;

#@vobs = `ct lsvob -s -host blrcc1`;
@vobs= ("\\scm_blr_amor", "\\scm_blr_projects", "\\scm_blr_misc", "\\blr_mobile_projects", "\\blr_mobile_test");
if ($ENV{OS} =~ m/Windows/)
{
$store = $ENV{SystemDrive};
open (VSU, ">$report") or die "Cannot Open:$!\n";
open (VS, ">>$report") or die "Cannot Open:$!\n";
$ct = "cleartool";
}
else
{
open (VSU, ">E:\\admin\\VOBSpaceUsage\\vobspaceusage.html") or die "Cannot Open:$!\n";
$ct = "C:\\Program Files\\Rational\\ClearCase\\bin\\cleartool.exe";
}
push (@vsu, start_html("Vob Space Usage Report"),"\n");
push (@vsu, "<p><b>VOB Backup Process Completed Successfully on Backup Server: <font color=blue>BLRSTG01</font color></b>");
push (@vsu, "<p>The VOBs are backed-up and available at the location: \\blrstg01\Clearcase\Backups folder.</p>");
push (@vsu, "\n<td width=auto align=center>======================================================================================= =\n");
push (@vsu, "<p><b>VOB Size Status on VOB Server: <font color=blue>BLRCC1 </font color></b></p>");
push (@vsu, "<table border=1 width=auto>\n");
push (@vsu, "<tr>\n");
push (@vsu, "<td width=auto align=center><b>Vob Name</b></td>\n");
push (@vsu, "<td width=auto align=center><b>Size in Mb</b></td>\n");
push (@vsu, "<td width=auto align=center><b>Size in Gb</b></td>\n");
push (@vsu, "</tr>\n");
push (@vs, "</table>");

foreach $vob (@vobs)
{
$vobname=$vob;
chomp($vobname);
push (@vsu, "<tr>\n");
push (@vsu, "<td width=auto align=left> $vobname </td>\n");
@vbpath= `ct lsvob $vob`;
foreach $path (@vbpath)
{
# print "\n$path";
$path =~ s/\*//;
$path =~ s/\s//;
# print "\n$path";
if ($path =~ /\s(\\\\[A-Za-z\\a-z0-9\_\.\\]*)/)
{
#print "\nVOBPATH --> $1 \n";
$cdft = "$1\\c\\cdft";
#print LOG "\t$cdft";
$ddft = "$1\\d\\ddft";
#print LOG "\t$ddft";
$db = "$1\\db";
#print LOG "\t$db";
$sdft = "$1\\s\\sdft";
#print "\n Source Pool ---> $sdft";
$vobpath = $1;
#print "\nVOBPath>>>>>>>$vobpath";
}
}
@totspace = `diruse /m $vobpath`;
@a=split(" ",$totspace[-1]);
$totalvobsize = $a[0];
# print LOG "\t\t$totalvobsize";
push (@vsu, "<td width=auto align=center> $totalvobsize </td>\n");
$totalGBsize = ($totalvobsize / 1024);
# print LOG "\t\t$totalGBsize";
push (@vsu, "<td width=auto align=center> $totalGBsize </td>\n");

}
#push (@vs, "<p>Disk Usage of <b>C</b> Drive</p>\n");

#push (@vs, "<p>Disk Usage of <b>E</b> Drive(VOBs Storage included)</p>\n");
#foreach(@msg)
#{
# print $_;
#}
foreach (@vsu)
{
print LOG;
}
#push (@vsu, <table>);
foreach (@vs)
{
print LOG;
print RLOG;
}
open (RLOG, "<E:\\Backups\\log\\rlog.txt");
@rlog = <RLOG>;
for( @rlog ){
# print if /Disk Usage/ .. 0
push (@du, $_) if /Disk Usage/ .. 0
}
$seen =1;
foreach $line(@du)
{
# @new= split(/\s/,$_);
chomp($line);
# print "\n$line";
if (($line =~ /^[0-9]*/) && ($line =~ /free$/))
{
@val = split(/\s/,$line);
$new = $val[0];
$new = sprintf "%.2f", $new;
# print "\nI am processing C drive info, The value of new variable is $new";
if ($new < 100.00)
{
print "\nThe Free space on BLRCC1 C drive is less than 100 GB, Please Upgrade/Free some space on the disk";
}
# else
# {
print "\nThe available free space on BLRCC1 C drive is $new";
# }
$val[0] = 0;
$seen=0;
}
$seen=2;
# print "\nLooped :$seen \n";
if (($line =~ /^[0-9]*/) && ($line =~ /free$/) && ($seen ==2))
{
@val = split(/\s/,$line);
$raghu = $val[0];
# print "\nValue is $val[0] \n";
$raghu = sprintf "%.2f", $raghu;
# print "\nI am processing E drive info, The value of new variable is $raghu";
if ($raghu < 100.00)
{
print "\nThe Free space on BLRCC1 E drive is less than 100 GB, Please Upgrade/Free some space on the disk";
}
# else
# {
print "\nThe available free space on BLRCC1 E drive is $raghu";
# }
}
print LOG "<p>$line</p>";
push (@vs, "<p>$line</p>\n");
}
close RLOG;
close LOG;
close VS;
close VSU;

Right now I am getting the output as shown below:

The available free space on BLRCC1 C drive is 103.82
The available free space on BLRCC1 E drive is 103.82
The available free space on BLRCC1 C drive is 145.17
The available free space on BLRCC1 E drive is 145.17

Expected output :

The available free space on BLRCC1 C drive is 103.82
The available free space on BLRCC1 E drive is 145.17
# 2  
Old 02-11-2009
Your output is inside the "foreach $line(@du)" loop, so if @du has two elements, you'll get the output twice.

HTH

Jerry
# 3  
Old 02-12-2009
Next time use the code tags and post formatted code. Trying to read that much unformatted code is too difficult. I think Jerry has spotted the problem though.
# 4  
Old 02-12-2009
Perl print error

Hi Kelvin and Jerry,

Thanks for your inputs. I will adhere in future.

I hope there should be two else conditions and the flag ($seen) will be true for both the cases and hence it prints twice at each loop.

Thanks Again,
ccsaviour
# 5  
Old 02-12-2009
You can't have two else conditions in perl. You can have:

if/elsif/else

with as many 'elsif' conditions as needed and the 'else' on the end is optional
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help in Perl Script for printing next line

I got multiple of documents in which i have to extract a line coming after a ID..The scenario is Customer ID: none VT : 002/89 Customer ID: Yes VT: 001/89 Customer ID: none VT: 006/85 Customer ID: Yes VT: 003/56 I have to extract the id which is coming after YES..The output... (7 Replies)
Discussion started by: rajkrishna89
7 Replies

2. Shell Programming and Scripting

help with perl database printing

Hey guys i am using perl and trying to pull a list of books from a database and then populate the list in a separate TT2 file. When the list is generated there should be 39 book names. When I do the foreach statement in my tt2 below, the first statement gives me 39 Array(random number) and the... (1 Reply)
Discussion started by: Joey12
1 Replies

3. Shell Programming and Scripting

Perl: selective printing of lines

Hi, I have a file with lines like this. 2 7 18 ggcgt anna 2 7 18 hhchc sam 3 7 18 hhdjcc ross 4 7 18 hhcjd jenny 0 8 21 jjdhs sam 3 8 21 kkok bush 2 9 24 kosss BrenhamIf the values of the second column are equal, print only those lines with the least first column value. So in... (5 Replies)
Discussion started by: polsum
5 Replies

4. Emergency UNIX and Linux Support

Perl - Retrieving and Printing Security Token

My script below is supposed to log in to my vB account on any vB forum I'm registered on and retrieve + print my security token. However it seems to be hit and miss. The logging in works perfectly just will not retrieve and print the security token for every forum I log in to. Code Below: ... (3 Replies)
Discussion started by: AndrewTwain
3 Replies

5. Shell Programming and Scripting

Printing between 2 matches with Perl

Can we please modify this perl one-liner to print lines between pattern1 and pattern2 in a file? Currently it prints lines till pattern2. (4 Replies)
Discussion started by: anand_bh
4 Replies

6. Shell Programming and Scripting

PERL - printing a hash of hashes to screen

Hi there I have a hash of hashes made up of the following data bge0|100|half|10.36.100.21 bge1|1000|full|10.36.100.22 bge2|1000|full|10.36.100.23 which when i turn into a hash, would look like this inside the system bge0 -> nic_speed -> 100 nic_duplex -> half ... (6 Replies)
Discussion started by: hcclnoodles
6 Replies

7. Shell Programming and Scripting

[Perl] Printing - Scalars

Hey Guys, I have some weird problem with printing scalars ... When I'm executing script both are printing in terminal ... But only one is printed to the file ? I don't know whats going on .. :) Btw .. I'm noobie :) took me lots of time to put this simple script together :) Thank you... (3 Replies)
Discussion started by: NDxiak
3 Replies

8. Shell Programming and Scripting

Need help in printing a sql query in perl

Hi All, I have the following sql query select abcd from udbadm.log where xyz='1'. I have 16k queries similar to this with different values for xyz. I want to print the values of 'abcd' for each row. I have the following perl code, but not sure how i can print that particular... (1 Reply)
Discussion started by: userscript
1 Replies

9. UNIX for Dummies Questions & Answers

Perl, printing a string into columns

How can I use Perl to a take a string of 10 characters and print the last five characters of the string in columns 1-5 and the first five in columns 6-10? Result: 0123456789 5 0 6 1 7 2 8 3 9 4 (5 Replies)
Discussion started by: doubleminus
5 Replies

10. Shell Programming and Scripting

printing an empty line in a file (perl)

I know this must be really easy, but i can't get it to work I've got a perl script, with a file. I want to print an empty line, and the following doesn't seem to work: print nameoffile "\n" thanks for your help!! (3 Replies)
Discussion started by: kfad
3 Replies
Login or Register to Ask a Question