-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileSizes
More file actions
193 lines (184 loc) · 8.19 KB
/
Copy pathFileSizes
File metadata and controls
193 lines (184 loc) · 8.19 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#! /usr/bin/perl
use 5.16.1;
use strict;
use warnings;
use File::Find;
use Scalar::Util qw(looks_like_number);
use Switch;
#Name: Eli Harris
#Email: ehharris@rams.colostate.edu
#Date: 12/9
#Class: CT320
#Assign: HW7/sizes
my $check = 0;
my $dir;
my $count = 0;
my $size = 0;
if ($#ARGV eq -1){
die "$0: No quota files entered to test";
}
sub size {
# we get each filename in $_
return unless -f;
my $file_size = -s $_;
$size += $file_size;
$count++;
#print "Found $_ $file_size Bytes\n";
}
foreach my $fileName(@ARGV) {
open(my $fh, $fileName) or die "$0: Couldn't open file '$fileName' \!";
while (my $row = <$fh>) {
chomp $row;
my $firstChar = substr($row, 0, 1);
if ($firstChar ne "#" && $row ne ""){
if ($check eq 0){
$dir = $row;
$check = 1;
if ($firstChar eq "/"){
if(! -d "$dir"){
die "$0: $dir is not vaild a directory!\n";
}
}
else {
my $userName = $row;
if ($firstChar eq "~") {
my @words = split /~/, $row;
$userName = $words[1];
}
my $check2 = 0;
while((my $name, my $passwd, my $uid, my $gid, my $quota, my $comment, my$gcos, my $homeDir, my $shell) = getpwent()) {
if ($userName eq $name){
$dir = $homeDir;
$check2 = 1;
}
}
if (! -d $dir){
$check2 = 0;
}
if ($check2 ne 1){
die "$0: $userName does not have a vaild home directory on this system!\n";
}
}
}
else {
#calc size and # of files
opendir my $dh, $dir or die "$0: Can't open $dir, bad directory given!";
closedir($dh);
find( \&size, $dir );
my $secChar = substr($row, 1, 1);
#size of plain files
my $val = substr($row, 2);
if ($firstChar eq "t"){
if ($secChar eq ">"){
if (looks_like_number($val)){
if ($size lt $val){
print "$dir: total minimum of $val voilated\n";
}
} else {
my $tempVal = $val;
my $letter = chop $val;
$letter = uc $letter;
switch ($letter) {
case "D" { $val = $val * 12; }
case "S" { $val = $val * 20; }
case "H" { $val = $val * 100; }
case "M" { $val = $val * 100000000; }
case "B" { $val = $val * 1000000000; }
else { die "$0: $letter isn't valid syntax\n"; }
}
if($val gt 1000000000000){
die "$0: value $val violates max value to be tested, value must be at or under 1 Trillion\n";
}
if($size lt $val){
print "$dir: total minimum of $tempVal voilated\n";
}
}
}
elsif ($secChar eq "<"){
if (looks_like_number($val)){
if ($size gt $val){
print "$dir: total maximum of $val voilated\n";
}
} else {
my $tempVal = $val;
my $letter = chop $val;
$letter = uc $letter;
switch ($letter) {
case "D" { $val = $val * 12; }
case "S" { $val = $val * 20; }
case "H" { $val = $val * 100; }
case "M" { $val = $val * 100000000; }
case "B" { $val = $val * 1000000000; }
else { die "$0: $letter isn't valid syntax\n"; }
}
if($val gt 1000000000000){
die "$0: value $val violates max value to be tested, value must be at or under 1 Trillion\n";
}
if($size gt $val){
print "$dir: total maximum of $tempVal voilated\n";
}
}
} else {
die "$0: Incorrect syntax on check $row!\n";
}
} elsif ($firstChar eq "n"){
if ($secChar eq ">"){
if (looks_like_number($val)){
if ($size lt $val){
print "$dir: number minimum of $val voilated\n";
}
} else {
my $tempVal = $val;
my $letter = chop $val;
$letter = uc $letter;
switch ($letter) {
case "D" { $val = $val * 12; }
case "S" { $val = $val * 20; }
case "H" { $val = $val * 100; }
case "M" { $val = $val * 100000000; }
case "B" { $val = $val * 1000000000; }
else { die "$0: $letter isn't valid syntax\n"; }
}
if($val gt 1000000000000){
die "$0: value $val violates max value to be tested, value must be at or under 1 Trillion\n";
}
if($size lt $val){
print "$dir: number minimum of $tempVal voilated\n";
}
}
} elsif ($secChar eq "<"){
if (looks_like_number($val)){
if ($size gt $val){
print "$dir: number maximum of $val voilated\n";
}
} else {
my $tempVal = $val;
my $letter = chop $val;
$letter = uc $letter;
switch ($letter) {
case "D" { $val = $val * 12; }
case "S" { $val = $val * 20; }
case "H" { $val = $val * 100; }
case "M" { $val = $val * 100000000; }
case "B" { $val = $val * 1000000000; }
else { die "$0: $letter isn't valid syntax\n"; }
}
if($val gt 1000000000000){
die "$0: value $val violates max value to be tested, value must be at or under 1 Trillion\n";
}
if($size gt $val){
print "$dir: number maximum of $tempVal voilated\n";
}
}
}
else {
die "$0: Incorrect syntax on check $row!\n";
}
}
else {
die "$0: $row is not a vaild check!\n";
}
}
}
}
}