I need to schedule a weekly report that will run every Sunday at 10:00 PM that will show all accounts (usernames and IP addresses) that have logged into the server. This output would be sent to the email.
I would like to make use of "last" & "mail" commands for this purpose.
The cron would look something like the below but the '-a' option will list the entire logged in users info. Whereas, I'm looking for the users info who have logged in the previous week only. How this can be achieved?
0 22 * * 0 /usr/bin/last -a | mail -s "SSH Logins Report" -r firstname.lastname@example.org
OS: CentOS Linux release 7.5