Skip to content

Instantly share code, notes, and snippets.

@digizeph
Created April 23, 2015 05:54
Show Gist options
  • Select an option

  • Save digizeph/085b527e4728a278b553 to your computer and use it in GitHub Desktop.

Select an option

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.
#!/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