This line should print "First" if it's the first login by user "user" since reboot from non-local host:
[ $( last | sed '/^reboot/,$d' | egrep '^user +pts/' | wc -l ) -lt 2 ] && echo First
Note that the last
log is usually rotated monthly, so the answer might be incorrect if the user has logged in more than one month ago.
I anchor the expression with ^
to make sure the user name is picked from the first column (should the user's name be still, we'd get a false hit on lines reading still logged in :-) and I also expect pts/
to appear, indicating a remote login (local logins are indicated with tty
instead).
This should work even if the computer hasn't been rebooted current month. But it would not work if your user's login name is verbatim reboot.