Specified log in time for users

I have this task : Check the logintime.txt every minute to only allow user to log in at the specified time.

logintime.txt has the following content: USER TIME_START TIME_STOP
Example:

 
john 17:00 18:00

My idea is locking the user at the TIME_STOP and unlocking at the TIME_START

while read line
do
USER=$(echo $line | awk '{print $1}')
TIME_START=$(echo $line | awk '{print $2}')
TIME_STOP=$(echo $line | awk '{print $3}')
at $TIME_START << EOF
passwd -l $USER
EOF
at $TIME_STOP << WTH
passwd -u $USER
WTH
done < logintime.txt

Any better idea to do this? Because my solution don't do the 'check file every minute' thing. And I don't understand why we need to do that thing.

while read USER TIME_START TIME_STOP # Get rid of echo and awk by using shell's IFS
do
at $TIME_START << EOF
passwd -l $USER
EOF
at $TIME_STOP << WTH
passwd -u $USER
WTH
sleep 60 # This should let a minute pass
done < logintime.txt

Well, isn't that your requirement?

my boss's requirement. About sleep 60, isn't it only runs the while loop every 60 seconds when we run the script ?

The checking every minute bit seems unnecessary.

Do you need to kill the session(s) which are active in that user's closed period? Even then you could issue an "at" job at the appropriate time.

It may mean the person specifying the script did not know about Linux unix "at" command or about special options to "passwd" on certain Linux platforms (it won't work on unix).

@balajesuri
I can't see the point of your sleep unless there is an issue with the number of concurrent "at" jobs. Also, if there list is very long the script could take hours to run.

I've figured it out myself.

Checking every minute to get the current time. If it is = TIME_STOP, kill the session of that user (use pkill -KILL -u username) and also lock the username

Thanks for your reply.