Conditions based on the number of fields
If a user logs onto the server's physical console directly rather than logging on through a remote or graphical pseudo-terminal, then the lastlog
output will not display the host field. To demonstrate this, I have logged onto my CentOS host directly to the tty1
console and avoided the GUI. The output from the previous awk control file shows that we now have the users tux and bob; bob though is lacking the host field as he is connected to a console.
Although in itself it's not an issue but it will be if we want to filter the fields and the two row's field numbers will vary where a field is omitted from some lines. For lastlog
we will have 9
fields for most connections and only 8
fields for those that connect directly to the server console. The desire for the application is that we print the username and the date, but not the time of the last login. We will also print our own header in the BEGIN
block. To ensure that we use the correct...