Created
April 23, 2015 05:54
-
-
Save digizeph/085b527e4728a278b553 to your computer and use it in GitHub Desktop.
Question: write a script to check who has logged in into your machine in the past month and log this information (usernames and last login) to a file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| onemonth=`date --date="1 month ago" +"%y%m%d"` | |
| last -F -R| head -n -2| cut -c1-9,27-46 | grep -v "reboot"| while read line; do date=`date -d "$(echo $line | awk '{ print $2" "$3" "$4" "$5 }')" +"%y%m%d"`; [[ $date -ge "$onemonth" ]] && echo $line; done > output.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment