raspberrypi-motd icon indicating copy to clipboard operation
raspberrypi-motd copied to clipboard

last: invalid option -- '-'

Open VictorioBerra opened this issue 9 years ago • 12 comments

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

VictorioBerra avatar Apr 08 '15 13:04 VictorioBerra

+1

alexanderscott avatar Jun 03 '15 13:06 alexanderscott

:+1:

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

nodesocket avatar Jun 07 '15 23:06 nodesocket

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

wikijm avatar Sep 19 '15 16:09 wikijm

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 }')
  1. 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

PenguinPaws avatar Jan 05 '16 06:01 PenguinPaws

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

kszere avatar Nov 23 '16 20:11 kszere

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" [email protected] 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 .

VictorioBerra avatar Nov 23 '16 21:11 VictorioBerra

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.

JoeArcher007 avatar Nov 29 '16 18:11 JoeArcher007

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 avatar Feb 09 '17 16:02 vidia

I fixed it here: lines 113 and 123.

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

vidia avatar Feb 09 '17 16:02 vidia

@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 avatar Apr 18 '17 05:04 NotMyFirstChoice

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

NotMyFirstChoice avatar Apr 18 '17 18:04 NotMyFirstChoice

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.

UsernamesAreForChumps avatar Jul 30 '17 22:07 UsernamesAreForChumps