Writw a shell script that determines the period for which a specific user logged in
Answers
Explanation:
If you're looking for the date of the user's last login, some systems provide it directly, for example lastlog -u "$USER_NAME" on Linux or lastlogin "$USER_NAME" on FreeBSD.
It's also available in the output of finger, but not in an easy-to-parse form. In any case, it's available in the output of last (on many unix variants, last -n 1 "$USER_NAME" shows the last login; otherwise you can do last "$USER_NAME" | head -n 1).
❌Note that last login may not correspond to the last logout (e.g. a user remained connected from one origin for a long time and made a quick network login recently).
Answer:
Explanation:
a=`date +%M`
b=`expr $a + 1`
while [ $b -gt `date +%M` ]
do
who | grep $1
if [ $? -eq 0 ]
then
echo "$1 has logged in 1 minute"
exit
fi
done
echo "$1 has not looged in within 1 minute