Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Last Login....: None #8

Open
WouterVdS opened this issue Jan 13, 2017 · 9 comments
Open

Last Login....: None #8

WouterVdS opened this issue Jan 13, 2017 · 9 comments

Comments

@WouterVdS
Copy link

The 'last login' line doesn't work for me. I'm on a Pi Zero with:
PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
NAME="Raspbian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=raspbian
ID_LIKE=debian

I also got the 'last: invalid option -- '-'' problem (see other issue) but PenguinPaws's comment fixed that!

@vidia
Copy link

vidia commented Feb 9, 2017

I fixed this here: https://gist.github.com/vidia/5d760a27cec2b9bd318dcc5c636c5a1d#file-motd-sh-L113

and line 123 as well.

@WouterVdS
Copy link
Author

Still not working for me, replaced both lines 113 and 123

@DoctorOctagonapus
Copy link

I'm getting the same issue. I've replicated the highlighted line and it doesn't show a usage error, but it's still printing None under login. I'm guessing there's a problem either with the If statement or the value $loginDate.

@NotMyFirstChoice
Copy link

I was having the same issue. I applied the fixes from @vidia, but it still didn't work until I made one more change. On line 122 from @vidia's link above the IF statement is looking for a "T" in the $loginDate string and on my Raspberry Pi that doesn't exist, so I changed the if [[ $loginDate == T ]]; to if [[ $loginDate != T ]];. Now it works.

@NotMyFirstChoice
Copy link

NotMyFirstChoice commented Apr 18, 2017

Don't use my fix listed above, It has issues on some days of the week. There may be better ways to fix it, but for now I just changed it to $loginDate == * instead of $loginDate == *T*. This is more of a hack, but I think it will be okay for now.

if [[ $loginDate == * ]]; then
login="$(date -d "$loginDate" +"%A, %B %d %Y, %T") ($loginIP)"
else
# Not enough logins
login="None"
fi

@UsernamesAreForChumps
Copy link

UsernamesAreForChumps commented Jul 30, 2017

signed up for github just to leave this fix! hope that it works for all... i dont know if i am supposed to modify the code with this slightly hackish fix or just leave it, but at least i'll leave a comment with how i fixed it...

the issue for this is that the "--time-format" switch is not supported on this version of the date command for whatever reason. the work around i cobbled together involves line 100:

original code:
read loginFrom loginIP loginDate <<< $(last $me --time-format iso -2 | awk 'NR==2 { print $2,$3,$4 }')

modified (and added line) code:
read loginFrom loginIP loginMonth loginDay loginTime loginYear <<< $(last $me -2 -F | awk 'NR==2 { print $2,$3,$5,$6,$7,$8 }')
loginDate=$( date -d "${loginDay}-${loginMonth}-${loginYear} ${loginTime}" +'%FT%T' ) # format date to ISO

the key difference is that it changes the date to display the full date with the -F switch, and pulls all of the individual date elements followed up by the next command to join all of the different strings into the ISO formatted string that the later code (if [[ $loginDate == T ]]; then...), that particular if is looking for the "T" that is present in an iso formatted timestamp which was originally designed to come from the "--time-format iso" portion.

@DoctorOctagonapus
Copy link

I tried that fix but couldn't get it to work for some reason. With your modified code it displays the login IP but no data to the left of that.

@UsernamesAreForChumps
Copy link

UsernamesAreForChumps commented Aug 2, 2017

what is the output of

# last -2

---EDIT---
disregard my question, i see the issue is that for some reason when i added the code it inserted an extra space between the $FT and %T, they should be all together. i have edited the fix in the original post.

@DoctorOctagonapus
Copy link

Yep that fixed it! Awesome thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants