I want to fetch user's login time and login date, is there any command in Unix providing User's login date and User's login time ? this problem i want to perform in Shell-script where username is accepting from the end-user and after checking the availability of user, i would like to fetch that user's login time and login date in different variable and then display using 'echo' command.
User’s Login date and login time
loginusers
Best Answer
For past logins:
Also, the command
who
lists current logins.If you're looking for the date of the user's last login, some systems provide it directly, for example
lastlog -u "$USER_NAME"
on Linux orlastlogin "$USER_NAME"
on FreeBSD. It's also available in the output offinger
, but not in an easy-to-parse form. In any case, it's available in the output oflast
(on many unix variants,last -n 1 "$USER_NAME"
shows the last login; otherwise you can dolast "$USER_NAME" | head -n 1
). Note that last login may not correspond to the last logout (e.g. a user remained connected from one origin for a long time and made a quick network login recently).