How to print last login time?
up vote
4
down vote
favorite
I'd like to know how to set in .bashrc file to print the last login time of users when logging into another user in terminal. I do know that with who or last, but I'd like something a little more customizable that can be formatted and only runs once per login, preferably to show in a format like so;
last login time [ 2015-02-13 @ 3:50:00 AM ]
user@host /path/dir/here $
that gets printed to the terminal screen before the bash prompt, and if possible to set and format color on the time and date stamp. How can I achieve this to customizing the bash prompt output?
linux bash shell bashrc
add a comment |
up vote
4
down vote
favorite
I'd like to know how to set in .bashrc file to print the last login time of users when logging into another user in terminal. I do know that with who or last, but I'd like something a little more customizable that can be formatted and only runs once per login, preferably to show in a format like so;
last login time [ 2015-02-13 @ 3:50:00 AM ]
user@host /path/dir/here $
that gets printed to the terminal screen before the bash prompt, and if possible to set and format color on the time and date stamp. How can I achieve this to customizing the bash prompt output?
linux bash shell bashrc
add a comment |
up vote
4
down vote
favorite
up vote
4
down vote
favorite
I'd like to know how to set in .bashrc file to print the last login time of users when logging into another user in terminal. I do know that with who or last, but I'd like something a little more customizable that can be formatted and only runs once per login, preferably to show in a format like so;
last login time [ 2015-02-13 @ 3:50:00 AM ]
user@host /path/dir/here $
that gets printed to the terminal screen before the bash prompt, and if possible to set and format color on the time and date stamp. How can I achieve this to customizing the bash prompt output?
linux bash shell bashrc
I'd like to know how to set in .bashrc file to print the last login time of users when logging into another user in terminal. I do know that with who or last, but I'd like something a little more customizable that can be formatted and only runs once per login, preferably to show in a format like so;
last login time [ 2015-02-13 @ 3:50:00 AM ]
user@host /path/dir/here $
that gets printed to the terminal screen before the bash prompt, and if possible to set and format color on the time and date stamp. How can I achieve this to customizing the bash prompt output?
linux bash shell bashrc
linux bash shell bashrc
edited Nov 30 '17 at 9:54
Rui F Ribeiro
38.5k1479128
38.5k1479128
asked Feb 12 '15 at 16:57
user91679
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
3
down vote
accepted
(Just as a guideline, the format is not exactly the same):
ll=$(last -1 -R $USER | head -1 | cut -c 20-)
export PS1="last login time [$ll]"'nh:W$ '
Edit: if you want last information to be printed only once (wise idea)
ll=$(last -1 -R $USER | head -1 | cut -c 20-)
echo "last login time [$ll]" # adjust to your login messages, fortunes, etc
export PS1='nh:W$ ' # replace by your favorite prompt
This works okay… but this doesn't just print that one time after logging in via terminal, it appears after each command is finished. Perhaps there is a way to improve on this answer so it only runs once after logging in.
– user91679
Feb 13 '15 at 8:44
There is always space for improvement, that is the goal of SO! (edited)
– JJoao
Feb 13 '15 at 9:16
add a comment |
up vote
0
down vote
Try putting the following line into your /etc/profile file ...
echo "your last login: `last -1 -R $USER` "
This will limit the results to 1 line and report the user's last login, during the login process. Afterwards it will not re-occur until the next login.
I'd recommend the user's personal ~/.bashrc file over the system-wide one, in case other users are not interested in such output. Otherwise, this seems to use the code from JJoao's answer and so should be credited there.
– Jeff Schaller
Nov 29 at 19:29
I'm not so interested in who gets the credit but in helping out. Thanks for pointing that out though.
– Richard A. Allcorn - rAllcorn
Dec 5 at 17:37
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
(Just as a guideline, the format is not exactly the same):
ll=$(last -1 -R $USER | head -1 | cut -c 20-)
export PS1="last login time [$ll]"'nh:W$ '
Edit: if you want last information to be printed only once (wise idea)
ll=$(last -1 -R $USER | head -1 | cut -c 20-)
echo "last login time [$ll]" # adjust to your login messages, fortunes, etc
export PS1='nh:W$ ' # replace by your favorite prompt
This works okay… but this doesn't just print that one time after logging in via terminal, it appears after each command is finished. Perhaps there is a way to improve on this answer so it only runs once after logging in.
– user91679
Feb 13 '15 at 8:44
There is always space for improvement, that is the goal of SO! (edited)
– JJoao
Feb 13 '15 at 9:16
add a comment |
up vote
3
down vote
accepted
(Just as a guideline, the format is not exactly the same):
ll=$(last -1 -R $USER | head -1 | cut -c 20-)
export PS1="last login time [$ll]"'nh:W$ '
Edit: if you want last information to be printed only once (wise idea)
ll=$(last -1 -R $USER | head -1 | cut -c 20-)
echo "last login time [$ll]" # adjust to your login messages, fortunes, etc
export PS1='nh:W$ ' # replace by your favorite prompt
This works okay… but this doesn't just print that one time after logging in via terminal, it appears after each command is finished. Perhaps there is a way to improve on this answer so it only runs once after logging in.
– user91679
Feb 13 '15 at 8:44
There is always space for improvement, that is the goal of SO! (edited)
– JJoao
Feb 13 '15 at 9:16
add a comment |
up vote
3
down vote
accepted
up vote
3
down vote
accepted
(Just as a guideline, the format is not exactly the same):
ll=$(last -1 -R $USER | head -1 | cut -c 20-)
export PS1="last login time [$ll]"'nh:W$ '
Edit: if you want last information to be printed only once (wise idea)
ll=$(last -1 -R $USER | head -1 | cut -c 20-)
echo "last login time [$ll]" # adjust to your login messages, fortunes, etc
export PS1='nh:W$ ' # replace by your favorite prompt
(Just as a guideline, the format is not exactly the same):
ll=$(last -1 -R $USER | head -1 | cut -c 20-)
export PS1="last login time [$ll]"'nh:W$ '
Edit: if you want last information to be printed only once (wise idea)
ll=$(last -1 -R $USER | head -1 | cut -c 20-)
echo "last login time [$ll]" # adjust to your login messages, fortunes, etc
export PS1='nh:W$ ' # replace by your favorite prompt
edited Feb 13 '15 at 8:50
answered Feb 12 '15 at 17:22
JJoao
7,0041827
7,0041827
This works okay… but this doesn't just print that one time after logging in via terminal, it appears after each command is finished. Perhaps there is a way to improve on this answer so it only runs once after logging in.
– user91679
Feb 13 '15 at 8:44
There is always space for improvement, that is the goal of SO! (edited)
– JJoao
Feb 13 '15 at 9:16
add a comment |
This works okay… but this doesn't just print that one time after logging in via terminal, it appears after each command is finished. Perhaps there is a way to improve on this answer so it only runs once after logging in.
– user91679
Feb 13 '15 at 8:44
There is always space for improvement, that is the goal of SO! (edited)
– JJoao
Feb 13 '15 at 9:16
This works okay… but this doesn't just print that one time after logging in via terminal, it appears after each command is finished. Perhaps there is a way to improve on this answer so it only runs once after logging in.
– user91679
Feb 13 '15 at 8:44
This works okay… but this doesn't just print that one time after logging in via terminal, it appears after each command is finished. Perhaps there is a way to improve on this answer so it only runs once after logging in.
– user91679
Feb 13 '15 at 8:44
There is always space for improvement, that is the goal of SO! (edited)
– JJoao
Feb 13 '15 at 9:16
There is always space for improvement, that is the goal of SO! (edited)
– JJoao
Feb 13 '15 at 9:16
add a comment |
up vote
0
down vote
Try putting the following line into your /etc/profile file ...
echo "your last login: `last -1 -R $USER` "
This will limit the results to 1 line and report the user's last login, during the login process. Afterwards it will not re-occur until the next login.
I'd recommend the user's personal ~/.bashrc file over the system-wide one, in case other users are not interested in such output. Otherwise, this seems to use the code from JJoao's answer and so should be credited there.
– Jeff Schaller
Nov 29 at 19:29
I'm not so interested in who gets the credit but in helping out. Thanks for pointing that out though.
– Richard A. Allcorn - rAllcorn
Dec 5 at 17:37
add a comment |
up vote
0
down vote
Try putting the following line into your /etc/profile file ...
echo "your last login: `last -1 -R $USER` "
This will limit the results to 1 line and report the user's last login, during the login process. Afterwards it will not re-occur until the next login.
I'd recommend the user's personal ~/.bashrc file over the system-wide one, in case other users are not interested in such output. Otherwise, this seems to use the code from JJoao's answer and so should be credited there.
– Jeff Schaller
Nov 29 at 19:29
I'm not so interested in who gets the credit but in helping out. Thanks for pointing that out though.
– Richard A. Allcorn - rAllcorn
Dec 5 at 17:37
add a comment |
up vote
0
down vote
up vote
0
down vote
Try putting the following line into your /etc/profile file ...
echo "your last login: `last -1 -R $USER` "
This will limit the results to 1 line and report the user's last login, during the login process. Afterwards it will not re-occur until the next login.
Try putting the following line into your /etc/profile file ...
echo "your last login: `last -1 -R $USER` "
This will limit the results to 1 line and report the user's last login, during the login process. Afterwards it will not re-occur until the next login.
edited Nov 29 at 19:28
Jeff Schaller
37.4k1052121
37.4k1052121
answered Nov 29 at 19:01
Richard A. Allcorn - rAllcorn
312
312
I'd recommend the user's personal ~/.bashrc file over the system-wide one, in case other users are not interested in such output. Otherwise, this seems to use the code from JJoao's answer and so should be credited there.
– Jeff Schaller
Nov 29 at 19:29
I'm not so interested in who gets the credit but in helping out. Thanks for pointing that out though.
– Richard A. Allcorn - rAllcorn
Dec 5 at 17:37
add a comment |
I'd recommend the user's personal ~/.bashrc file over the system-wide one, in case other users are not interested in such output. Otherwise, this seems to use the code from JJoao's answer and so should be credited there.
– Jeff Schaller
Nov 29 at 19:29
I'm not so interested in who gets the credit but in helping out. Thanks for pointing that out though.
– Richard A. Allcorn - rAllcorn
Dec 5 at 17:37
I'd recommend the user's personal ~/.bashrc file over the system-wide one, in case other users are not interested in such output. Otherwise, this seems to use the code from JJoao's answer and so should be credited there.
– Jeff Schaller
Nov 29 at 19:29
I'd recommend the user's personal ~/.bashrc file over the system-wide one, in case other users are not interested in such output. Otherwise, this seems to use the code from JJoao's answer and so should be credited there.
– Jeff Schaller
Nov 29 at 19:29
I'm not so interested in who gets the credit but in helping out. Thanks for pointing that out though.
– Richard A. Allcorn - rAllcorn
Dec 5 at 17:37
I'm not so interested in who gets the credit but in helping out. Thanks for pointing that out though.
– Richard A. Allcorn - rAllcorn
Dec 5 at 17:37
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f184506%2fhow-to-print-last-login-time%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown