Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

We need a new mechanism to identify accounts that haven\'t been used in a while

ID: 3886552 • Letter: W

Question

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/lastlog1.out /usr/local/courses/clark/cs3423/2017Fa/Proj2/lastlog2.out Please note that lastlog returns a result similar to this: 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, xy/222, 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't 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 "lpt913". There are several ways to avoid this problem. Consider having two different sed scripts (one for each of the lastlog?.out files). One of the scripts could produce output which tell the pattern to match to the end of the line: ytang$ 1p$ The other sed script produces user IDs without the "S". Now the pattern 1p$ doesn't match 1pt913. Problem B: sed, cat, sort, and uniq -c For this problem, we will 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 cither have not logged in or haven't logged in during 2017 (i.e., we won't have a pattern like "1pS" in our files). Suppose we cat those files together and sort them. We can use uniq -c to get a count of each unique value We can then use sed to include only user IDs with a count of 2 and also remove the count.

Explanation / Answer

1.lastlog1.out | grep never | awk '{print $1}'

prints the users who are never logged

lastlog1.out | grep -e never -e 2017 | awk'{print $1}' > file1

lastlog2.out | grep -e never -e 2017 | awk '{print $1}' >file2

grep -Fx -f file1 file2------gives intersection of two files

sed 's/$/$/' file1 adds $ symbol at the end of each line in file 1

sed [A-Za-z]*$ file2

now file1 has $ symbol and file2 has no symbol.compare the two files.

problem b:

sed -n '/never/p' lastlog1.out |awk 'print{$1}' >file1

sed -n '/2017/p' lastlog1.out |awk 'print{$1}' >file2

cat file1 file2|sort|uniq -c >file3

sed 's/^2s*//' file3 |cut -d ' '

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote