I have a problem with a shell script. It is supposed to read arguments: index, date, time1 (the beginning of the interval), time2 (the end of the interval). It should count how many times the user(index) has logged on the given date in the time interval time1-time2.
For example : 121212 "Jan 14" 00 12
This works, but I have a problem with the argument date. It doesn't recognize it as one argument. It splits it in Jan and 14" which is a big problem. I've been searching on the internet for a few hours, but I couldn't find solution anywhere. Here is my code:
#!/bin/bash
read user date time1 time2
list=`last | grep ^$user.*$date | awk '{ print $7 }'`
start=$time1
end=$time2
echo "start $start"
echo "end $end"
count=0
for el in $list ;
do
login=$el
echo "najava $najava"
checkIf(){
current=$login
[[ ($start = $current || $start < $current) && ($current = $end || $current < $end) ]]
}
if checkIf; then
count=`expr $count + 1`
ip=`last | grep ^$user.*$date.*$login | awk '{ print $3 }'`
echo $ip >> address.txt
else
continue
fi
done
echo "The user has logged in $count times in the given time interval"
Aucun commentaire:
Enregistrer un commentaire