Advertisement

04.10.2008 at 11:10PM PDT, ID: 23314250
[x]
Attachment Details

Perl script help (Usage alert)

Asked by rdashokraj in Perl Programming Language

Hello,

I have a Perl script given in the snippet (Please refer http://www.experts-exchange.com/Programming/Languages/Scripting/Perl/Q_23283047.html). Now i would like to have a "Usage statement" when this script is executed without giving proper arguments. The usage statement can be as follows:  
"$0  [-t optional] [-a <days>, -m <days>, -c <days>] /filesystem_path".

Could you please help me in this? I tried with syntax as given below but it gives error like this: # ./netapp_check.pl /galaxy
HASH(0x40012f80)

die {"Usage: $0 [-a <Days>,-m <Days>,-c <Days>] /Filesystem_pathname (Refer ReadMe file) \n"} unless $aflag || $cflag || $mflag;


Thanks,
Ashok Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
#!/usr/bin/perl
 
use File::Find ("find");
use strict;
 
my (%time, @dirs, $total, $atime, $mtime, $ctime, $aflag, $cflag, $mflag, $tflag);
 
$mtime=0;
$ctime=0;
$atime=0;
 
while (1) {
        last unless $_=shift;
        if (/^-a$/) {$aflag=1; $atime=shift; exit 1 unless $atime =~ /^\d*$/}
        if (/^-m$/) {$mflag=1; $mtime=shift; exit 1 unless $mtime =~ /^\d*$/}
        if (/^-c$/) {$cflag=1; $ctime=shift; exit 1 unless $ctime =~ /^\d*$/}
        if (/^-t$/) {$tflag=1;}
        push @dirs,$_ unless /^-/;
}
die {"Usage: $0 [-a <Days>,-m <Days>,-c <Days>] /Filesystem_pathname (Refer ReadMe file) \n"} unless $aflag || $cflag || $mflag;
 
die {"Usage: $0 [-a <Days>,-m <Days>,-c <Days>] /Filesystem_pathname (Refer ReadMe file) \n"} unless @dirs;
 
for (@dirs) {
        print "\n ==> $_\n\n";
        find(\&wanted, $_);
        if ($tflag) {printf "\nTotal size of resultant files: %8.2f MB\n\n", $total / (1024 * 1024)};
        $total = 0;
}
 
sub wanted {
        if ($_ eq ".snapshot") {
                $File::Find::prune=1;
           }
        elsif ((-f || -d ) && -A > $atime && -C > $ctime && -M > $mtime)
           {
                my $size = -s;
                $total += $size;
                print `ls -l $File::Find::name`, "\n";
          #printf "%-75s\t%7d KB\n", $File::Find::name, ($size / 1024);
           }
}
[+][-]04.10.2008 at 11:15PM PDT, ID: 21331658

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.10.2008 at 11:22PM PDT, ID: 21331682

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.10.2008 at 11:38PM PDT, ID: 21331756

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Perl Programming Language
Sign Up Now!
Solution Provided By: ozo
Participating Experts: 1
Solution Grade: A
 
 
[+][-]04.11.2008 at 12:01AM PDT, ID: 21331845

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.11.2008 at 12:07AM PDT, ID: 21331863

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.11.2008 at 12:19AM PDT, ID: 21331907

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]04.11.2008 at 12:22AM PDT, ID: 21331917

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.11.2008 at 12:27AM PDT, ID: 21331934

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628