0
I have to write a shell script that returns all users online who logged in after a specified date.
I tried
who | cut -d' ' -f1 | sort | uniq
but I don't know how to put in the condition for the date to be later than the date I give manually.
0
I have to write a shell script that returns all users online who logged in after a specified date.
I tried
who | cut -d' ' -f1 | sort | uniq
but I don't know how to put in the condition for the date to be later than the date I give manually.
1
You can tackle this issue in a number of ways, I usually prefer using epoch to compare dates.
The date
command can easily convert to epoch (seconds since 1970-01-01 00:00:00 UTC):
Current date/time in epoch:
date +%s
1479994078
Convert any date to epoch:
date --date="19-FEB-12" +%s
1329620400
You can easily compare the dates in bash expanding the commands:
if [[ $(date +%s) >= $(date --date="19-FEB-12" +%s) ]]
then
...
fi
I also advise using
awk
to parse the output ofwho
, but that is up to you – Bruno9779 – 2016-11-24T13:41:38.777