(Solved) : Write Script Named Trackloginssh Purpose Script Parse Var Log Secure Log File Contains Inf Q37250432 . . .
write a script named track_logins.sh. The purpose ofthis script is to parse the /var/log/secure log file thatcontains information about all authentication successes andfailures on the system. Specifically, each line contains the time,user, and program involved each time a user tries to login orlogout of the system. For example, you might see lines likethis:
Mar 18 09:29:41 hostname gdm-password]:pam_unix(gdm-password:session): session opened for user spikes
Mar 18 14:42:18 hostname sshd[7001]: pam_unix(sshd:session):session opened for user spikes by (uid=0)
The first line shows that a user named ‘spikes’ loggedin to the GUI (gdm-password) at 9:29:41. Thesecond line shows that the same user logged in over SSH (remotely)at 14:42:18. Your script must find all similar lines in/var/log/secure and print them out in a nicer format. Youwill need to narrow down the lines that contain the information wewant (see the above examples), then extract the username, date,login type, and whether they logged in or out. Note that you’llneed to somehow filter out the gdm-launch-environmentlines as those are helpers used when other “real” users log in.Your script therefore should note print anything for those lines.Also note that you’ll need to start the sshd.service ifyou want to test logging in/out remotely. Here is an examplerun:
[user@user eclab]$ sudo ./track_logins.sh
username logged in remotely at Mar 30 19:17:27
username logged out remotely at Mar 30 19:18:02
username logged in locally at Mar 30 19:18:08
username logged out locally at Apr 2 09:29:35
username logged in locally at Apr 2 09:29:41
[user@user eclab]$
Expert Answer
Answer to write a script named track_logins.sh. The purpose of this script is to parse the /var/log/secure log file that contains …
OR