![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Perl Error | dirdamalah | Shell Programming and Scripting | 3 | 06-21-2008 05:32 PM |
| Perl, printing a string into columns | doubleminus | UNIX for Dummies Questions & Answers | 5 | 05-21-2008 09:41 PM |
| PERL Error | Asteroid | High Level Programming | 3 | 04-25-2008 01:15 AM |
| printing an empty line in a file (perl) | kfad | Shell Programming and Scripting | 3 | 05-07-2005 03:10 AM |
| Error message printing to Windows on port 515 | pauls | SUN Solaris | 0 | 12-23-2004 09:51 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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 |
|
||||
|
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 |
|
||||
|
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 |
| Sponsored Links | ||
|
|