-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfss_script.sh
More file actions
123 lines (108 loc) · 4.1 KB
/
fss_script.sh
File metadata and controls
123 lines (108 loc) · 4.1 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
#!/bin/bash
#Checks if the input call for the bash is correct..
while getopts ":p:c:" opt_arg; do
case ${opt_arg} in
p) path=$OPTARG;;
c) command=$OPTARG;;
\?) echo "Wrong input flags! Usage: ./fss_script.sh -p <path> -c <command>"; exit 1;;
:) echo "No input argument for flag :-$OPTARG! Usage: ./fss_script.sh -p <path> -c <command>"; exit 1;;
esac
done
#..don't forget to check if the <path>/<command> isn't NULL
if [ -z $path ] || [ -z $command ]; then
echo "Error. NULL Input argument"
exit 1
fi
#Check what is the command..
case "$command" in
listAll)
#If we are in a line with the bellow pattern(AKA message of a sync action)..
#..we need to save every time the new values of the variables we need to print
awk '/\[(FULL|MODIFIED|ADDED|DELETED)\]/ && /\[(SUCCESS|ERROR|PARTIAL)\]/ {
date = substr($1, 2)
time = substr($2, 1, length($2)-1)
source = substr($3, 2, length($3)-2)
target = substr($4, 2, length($4)-2)
status = substr($7, 2, length($7)-2)
date_time[source] = date " " time
final_target[source] = target
final_status[source] = status
}
END {
for (src in date_time) {
printf "%s -> %s [Last Sync: %s] [%s]\n", src, final_target[src], date_time[src], final_status[src]
}
}' "$path";;
listMonitored)
#Same with the above, but also..
#..we are taking track of the lines that inform us about..
#..if the <directory> is active or not(Print only the active ones)
awk '/Monitoring started for/ {
temp = substr($6, 1)
status[temp] = 1
}
/Monitoring stopped for/ {
temp = substr($6, 1)
status[temp] = 0
}
/\[(FULL|MODIFIED|ADDED|DELETED)\]/ && /\[(SUCCESS|ERROR|PARTIAL)\]/ {
date = substr($1, 2)
time = substr($2, 1, length($2)-1)
source = substr($3, 2, length($3)-2)
target = substr($4, 2, length($4)-2)
date_time[source] = date " " time
final_target[source] = target
}
END {
for (src in status) {
if (status[src] == 1) {
printf "%s -> %s [Last Sync: %s]\n", src, final_target[src], date_time[src]
}
}
}' "$path";;
listStopped)
#Same with the above, but..
#..print only the inactive ones
awk '/Monitoring started for/ {
temp = substr($6, 1)
status[temp] = 1
}
/Monitoring stopped for/ {
temp = substr($6, 1)
status[temp] = 0
}
/\[(FULL|MODIFIED|ADDED|DELETED)\]/ && /\[(SUCCESS|ERROR|PARTIAL)\]/ {
date = substr($1, 2)
time = substr($2, 1, length($2)-1)
source = substr($3, 2, length($3)-2)
target = substr($4, 2, length($4)-2)
date_time[source] = date " " time
final_target[source] = target
}
END {
for (src in status) {
if (status[src] == 0) {
printf "%s -> %s [Last Sync: %s]\n", src, final_target[src], date_time[src]
}
}
}' "$path";;
purge)
#Check if it is a directory..
if [ -d "$path" ]; then
echo "Deleting $path..."
rm -rf "$path"
echo "Purge complete."
elif [ -f "$path" ]; then #..or a file to delete it
echo "Deleting $path..."
rm -f "$path"
echo "Purge complete."
else #If it is not a directory or file..
echo "Wrong path! Cannot detect file or directory : $path" #..inform the user..
exit 1 #..and exit
fi
;;
#If the given command was not an option, inform the user and exit
*)
echo "Wrong command request! Commands: <listAll>, <listMonitored>, <listStopped>, <purge>"
exit 1;;
esac