Question: In UNIX Write a script that checks each minute and reports on who logs in and who logs out. You can follow the steps below
In UNIX
Write a script that checks each minute and reports on who logs in and who logs out.
You can follow the steps below (not the only way):
Using the commands who and cut, extract the list of usernames currently logged in the system
To check after a minute, the sleep command can be used: sleep 60
Get the new list of users logged in after a minute
For each user in the list;
check if he is in the second list using if and grep. You can dump the output of grep to /dev/null when using it in the as a test for the if statement
If the user is not in the second list, print that the user has logged out
For each user in the second list,
If he is in the first list, print that the user has logged in
Rename the second list as the first list
Repeat the process from step 2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
