Quote:
Originally Posted by Kustom42
Its a very intricate awk statement. I would stick to something simple for this task, no need to overkill it with awk.
|
Ummm ... conceptually what I'm doing there with awk is far simpler than the
two invocations of ssh & grepping & cutting ...
Code:
ssh $server "last" |
Same as yours, execute on each server ...
From here on it becomes different ... we handle all servers output locally,
just in case the implementations of tools differ on different platforms.
Reverse the output of last, so newest lines come out at the bottom
rather than at the top.
Code:
awk '$0 !~ /^[[:space:]]*$/ && $1 !~ /shutdown|reboot/ && $2 != "begins"
We tell awk to ignore lines that are
EMPTY, contain
shutdown or reboot in
the first field, or where the 2nd fiels is
begins.
So all we get it lines w/ usernames ... and they come in chronological order.
We now create an array a, with the username being the index, and store the
entire line in the array. So on every run where the same user appears the
content of the array element that matches the users name gets overwritten
with the most recent login event.
After the entire output of last has been processed we print all
array elements; in other words: all usernames with their last login date.
Code:
END{for(i in a){print a[i]}}'
Cheers,
Tink