-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileMount
121 lines (98 loc) · 3.01 KB
/
FileMount
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
#!/bin/bash
# Directory path - Change this to your target directory
DIR_PATH="/path/to/your/directory"
# Function to check if directory exists
check_directory() {
local dir_path=$DIR_PATH
if [ ! -d "$dir_path" ]; then
echo "Error: Directory '$dir_path' does not exist"
exit 1
fi
}
# Function to validate files and folders
validate_items() {
local dir_path=$DIR_PATH
local total_items=0
local error_count=0
local success_count=0
echo "Starting validation of directory: $dir_path"
echo "----------------------------------------"
# Loop through all items in directory
for item in "$dir_path"/*; do
((total_items++))
local item_status=0
echo "Checking: $item"
# Check if item exists
if [ ! -e "$item" ]; then
echo "ERROR: $item does not exist"
((error_count++))
continue
fi
# Check read permissions
if [ ! -r "$item" ]; then
echo "ERROR: $item is not readable"
((error_count++))
item_status=1
fi
# Directory specific checks
if [ -d "$item" ]; then
if [ ! -x "$item" ]; then
echo "ERROR: Directory $item is not traversable"
((error_count++))
item_status=1
fi
if [ ! -w "$item" ]; then
echo "WARNING: Directory $item is not writable"
fi
fi
# File specific checks
if [ -f "$item" ]; then
# Check if file is empty
if [ ! -s "$item" ]; then
echo "WARNING: $item is empty"
fi
# Get file size
size=$(du -k "$item" | cut -f1)
if [ $size -gt 102400 ]; then # 100MB = 102400KB
echo "WARNING: $item is larger than 100MB"
fi
fi
# Count successful validations
if [ $item_status -eq 0 ]; then
((success_count++))
fi
done
# Print validation summary
echo "----------------------------------------"
echo "Validation Results:"
echo "Total items checked: $total_items"
echo "Successfully validated: $success_count"
echo "Items with errors: $error_count"
return $error_count
}
# Main function
main() {
# Check if directory exists
check_directory
# Validate items in directory
validate_items
local status=$?
# Print final status
if [ $status -eq 0 ]; then
echo "Final Status: PASSED"
exit 0
else
echo "Final Status: FAILED"
exit 1
fi
}
# Execute main function
main
775 Permission:
Owner: 7 (rwx) - Full permissions (read, write, execute)
Group: 7 (rwx) - Full permissions (read, write, execute)
Others: 5 (r-x) - Can read and execute, but cannot write
777 Permission:
Owner: 7 (rwx) - Full permissions (read, write, execute)
Group: 7 (rwx) - Full permissions (read, write, execute)
Others: 7 (rwx) - Full permissions (read, write, execute)