Source From Here
- 09-1_list_of_logged_users.sh
Execution output:
- #!/bin/bash
- # Author: John Lee
- # Date: 2021/07/25
- # Description: This script will list users logged in by date
- # Info:
- # $ last | head -n 3
- # root pts/1 192.168.37.1 Sun Jul 25 00:16 gone - no logout
- # root pts/1 192.168.37.1 Sat Jul 24 18:41 - 20:33 (01:51)
- # root pts/1 192.168.37.1 Fri Jul 23 23:00 - 05:13 (06:13)
- # e.g.: Sun Jul 25
- today=`date | awk '{print $1,$2,$3}'`
- echo -n "Give month to search logged user(e.g: `date +'%b'`): "
- read month
- echo -n "Give day to search logged user(e.g.: `date +'%d'`): "
- read day
- if [ ! -z "$month" ] && [ ! -z "$day" ]; then
- tdate="$month\s+$day\s+"
- else
- tdate=$today
- month=`date +'%b'`
- day=`date +'%d'`
- fi
- echo "Search logged user on date='$month $day'"
- for u in `last | grep -P "${tdate}" | awk '{print $1}' | sort | uniq`
- do
- echo "Found user '$u'"
- done
沒有留言:
張貼留言