gagle / raspberrypi-motd

Message of the Day for the Raspberry Pi.
MIT License
194 stars 75 forks source link

last: invalid option -- '-' #6

Open VictorioBerra opened 9 years ago

VictorioBerra commented 9 years ago

Getting the above error on: Linux raspberrypi 3.18.7-v7+ #755 SMP PREEMPT Thu Feb 12 17:20:48 GMT 2015 armv7l GNU/Linux

alexanderscott commented 9 years ago

+1

nodesocket commented 9 years ago

:+1:

➜  ssh  sudo bash /etc/motd.sh
last: invalid option -- '-'
Usage: last [-num | -n num] [-f file] [-t YYYYMMDDHHMMSS] [-R] [-adioxFw] [username..] [tty..]
wikijm commented 9 years ago

Exact same issue. It's possible to replace "--time-format" by "-t" but an error with time format appears.

PenguinPaws commented 8 years ago

We can fix this by editing 2 lines in the original motd.sh script.

1) Line 100 (after #System Information) Change this to become:

read loginFrom loginIP loginDate loginTime <<< $(last $me | awk 'NR==2 { print $2,$3,$4,$7 }')

2) Line 109 (second IF condition paragraph after the #TTY login header) Change this to become:

login="$(date -d $loginDate +"%A, %d %B %Y,") $loginTime ($loginIP)"

This is based on http://pastebin.com/g0CrwQ7j, which I got from here: https://www.domoticz.com/forum/viewtopic.php?f=23&t=6738

kszere commented 7 years ago

Not solved this problem. After login I says "Last Login....: None "

VictorioBerra commented 7 years ago

Is it the same problem or a new one? If it's different create a new issue for it with steps to replicate.

On Nov 23, 2016 2:59 PM, "kszere" notifications@github.com wrote:

Not solved this problem. After login I says "Last Login....: None "

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/gagle/raspberrypi-motd/issues/6#issuecomment-262628531, or mute the thread https://github.com/notifications/unsubscribe-auth/ACzG6_E89q_C-rXAuzbjVpIl9LJyPqd-ks5rBKkhgaJpZM4D8bGg .

JoeArcher007 commented 7 years ago

To fix this, I did a probably crap workaround, but seems to work for me.

Distributor ID: Raspbian Description: Raspbian GNU/Linux 8.0 (jessie) Release: 8.0 Codename: jessie

Linux MyServer 4.4.32-v7+ #924 SMP Tue Nov 15 18:11:28 GMT 2016 armv7l GNU/Linux

106 # TTY login 107 #if [[ $loginDate == - ]]; then 108 # loginDate=$loginIP 109 # loginIP=$loginFrom 110 #fi 111 112 #if [[ $loginDate == T ]]; then 113 # login="$(date -d $loginDate +"%A, %d %B %Y, %T") ($loginIP)" 114 # login="($loginDate)($loginIP)" 115 #else 116 # Not enough logins 117 # login="None" 118 #fi 119 120 login=`last $me -n 2 -w -a | awk 'NR==2 { print $3,$4,$5,$6,$7,$8,$10 }'` 121 122 label1="$(extend "$login")" 123 #label1="$login" 124 label1="$borderBar $(color $statsLabelColor "Last Login....:") $label1$borderBar"

The above I commented out the old section and just creted everything from 120 to 124. Hopefully this is readable.

vidia commented 7 years ago

I am still having this issue on my install of the script.

I can't find any form of "last" that has the --time-format flag at all. So I am not sure where that came from honestly.

vidia commented 7 years ago

I fixed it here: lines 113 and 123.

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

NotMyFirstChoice commented 7 years ago

@vidia Thanks for the fix, but I had to make one more change before it worked for me. On line 122 from your 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 if [[ $loginDate == T ]]; to if [[ $loginDate != T ]];. Now it works.

NotMyFirstChoice commented 7 years ago

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 commented 7 years ago

reading through the errors, i realized that this is the same issue as #8 and that the fix is the same:

(fix copied from other issue)

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.