-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetMom.sh
More file actions
85 lines (78 loc) · 1.97 KB
/
getMom.sh
File metadata and controls
85 lines (78 loc) · 1.97 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
#!/bin/bash
#Downloading attendance.log
echo "Wait for a while..." #Displaying message in terminal for user
wget -o /dev/null https://inductions.delta.nitt.edu/sysad-task-1-attendance.log
cut -f 2,3,4 -d '-' sysad-task-1-attendance.log | cut -f 1 -d ',' | uniq > tempDates.txt #A temporary file(deleted at the end of this script) to get meetdates and create an array
#Getting all meetdates in an array
meetDates=()
while read p
do
meetDates+=($p)
done < tempDates.txt
exceed=${#meetDates[@]}
exceed=$[exceed-1]
#Generates an array with all last joined user with date (between given paramters)
lastJoined=()
getMom(){
local date="$1"
x=$(grep $date sysad-task-1-attendance.log | cut -f 1 -d '-' | tac | sed 's/_10/_00/g' | grep '_0' | head -1 | tr -d ' ')
if [ -z $x ]
then
lastJoined+=($(echo "n-$date" ))
else
case "_00" in
$x )
x=$(echo $x | sed 's/_00/_10/g') ;;
esac
lastJoined+=($(echo $x-$date))
fi
echo File created in home directory
}
if expr "$1" ">=" "${meetDates[0]}" > /dev/null && expr "$2" "<=" "${meetDates[$exceed]}" > /dev/null
then
for (( z=0; z<$exceed; z++ ))
do
if expr "${meetDates[$z]}" ">=" "$1" > /dev/null
then
x=$z
break
fi
done
for (( z=0; z<$exceed; z++ ))
do
if expr "${meetDates[$z]}" ">=" "$2" > /dev/null
then
if expr "${meetDates[$z]}" "=" "$2" > /dev/null
then
y=$z
break
else
y=$[z-1]
break
fi
fi
done
lim=$[$y+1]
for (( z=$x; z<$lim; z++ ))
do
getMom ${meetDates[$z]}
done
else
echo Sorry, wrong input.
fi
#Writing the MoM of each date with username into MoM file
echo -e "User\t\t\tDate\t\t\t\t\t\tMoM" > MoM
for i in ${lastJoined[@]}
do
x=$(echo $i | cut -f 1 -d '-')
y=$(echo $i | cut -f 2,3,4 -d '-')
if [ "$x" = "n" ]
then
echo -e "No second year in this meet\t$y" >> MoM
else
m=$(cat /home/$x/$y"_mom" 2> /dev/null)
echo -e "$x\t\t$y\t\t\t\t$m\n" >> MoM
fi
done
rm tempDates.txt
rm sysad-task-1-attendance.log