Nandakumar Edamana
Share on:
@ R t f

Login Status Using Shell Script

Code

#!/bin/sh

echo -n "Current date and time     : "
date

echo -n "Number of logged-in users : "
echo $(last | grep -c "still logged in")

echo -n "Terminal name             : "
tty

echo -n "Last login date and time in this terminal:"
echo "$(last $(tty) -F)" | awk '{ print $3 " " $4 " " $5 " " $7 " " $6 }'