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: invalid option -- '-' #6

Open
VictorioBerra opened this issue Apr 8, 2015 · 12 comments
Open

last: invalid option -- '-' #6

VictorioBerra opened this issue Apr 8, 2015 · 12 comments

Comments

@VictorioBerra
Copy link

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 VictorioBerra changed the title ./motd.sh: 5: ./motd.sh: Syntax error: newline unexpected . Apr 8, 2015
@VictorioBerra VictorioBerra changed the title . last: invalid option -- '-' Apr 8, 2015
@VictorioBerra VictorioBerra reopened this Apr 8, 2015
@alexanderscott
Copy link

+1

@nodesocket
Copy link

👍

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

@wikijm
Copy link

wikijm commented Sep 19, 2015

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

@PenguinPaws
Copy link

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

@kszere
Copy link

kszere commented Nov 23, 2016

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

@VictorioBerra
Copy link
Author

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
#6 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACzG6_E89q_C-rXAuzbjVpIl9LJyPqd-ks5rBKkhgaJpZM4D8bGg
.

@JoeArcher007
Copy link

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
Copy link

vidia commented Feb 9, 2017

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
Copy link

vidia commented Feb 9, 2017

@NotMyFirstChoice
Copy link

@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
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

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.

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

10 participants