Problem A: sed and grep -f we need a new mechanism to identify accounts that hav
ID: 3888607 • Letter: P
Question
Problem A: sed and grep -f we need a new mechanism to identify accounts that haven't been used in a while so that we can remove the accounts. We will use the lastlog tool to get information of the last time someone logged in; however, it just handles one server. For consistent results (and ease of grading), we have copied the output of lastlog for fox01 and fox02 to /usr/local/courses/clark/cs3423/2017Fa/Proj2/lastlogi.out /usr/local/courses/clark/cs3423/2017Fa /Proj2/lastlog2.out Please note that lastlog returns a result similar to this. ums 562 **Never logged in xyz 222 pts/3 173.227.72.99 Sun Aug 7 11:39:56 -0500 2015 fernandez pts/11 n0000d193 .cs.uts Wed Jan 13 11:13:49 - 0600 2016 rslavin pts/2 104.218.77.194 Tue Aug 15 10:11:37 -0500 2017 Clark pts/8 172.24.141.44 Fri Aug 18 13:07:29 -0500 2017 ytang Never logged in Copy those two lastlog?.out files to your code directory Find anyone who has either not logged in or hasn't logged in during 2017 for each of those lastlog files. In the example above, the following users meet the criteria: ums562, xyz222, fernandez, and ytang. The result file should only contain user IDs. The intersection of those result files gives us the people who didn't log into both of those servers during the desired time. Matching on 2017. Where is the 2017 we want to match which indicates that the user logged in during 2017? If we just match "2017", it could match actual login IDs that contain 2017 who haven'logged in during 2017. Intersection Use grep -f to help with getting the intersection. Unfortunately, some login IDs like "lp" could match an id like "Ipt913". There are several ways to avoid this problem. Consider having two different sed scripts (one for each of the last log?.out files). One of the scripts could produce output which tell the pattern to match to the end of the line: ytang$ IPS The other sed script produces user IDs without the "$". Now the pattern Ip$ doesn't match Ipt913. Problem B: sed, cat, sort, and uniq - For this problem, we wi want to get the same result, but with a different approach. Using one of the sed scripts from problem A, we can produce two files of user IDs that either have not logged in or haven't logged in during 2017 (i.e, we won't have a pattern like "lp$" in our files). Suppose we cat those files together and sort them. We can use uniq -c to get a count of each unique valueExplanation / Answer
Script :
#!/bin/bash
lastlog | tee lastLog.log
touch result.log
while IFS= read line
do
echo "$line"
year = $(sed 's/.*(....)//' $line)
if [ $year != "2017" ]
echo $line>>result.log
done <lastLog.log
awk '{print $1}' | tee p2a.out
Explanation:
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.