0

I need to know the last login yesterday and email it to me via crontab....

Since the last command shows all the login you need to scroll up. Using grep and cut might do the trick.

jmazaredo
  • 202
  • 5
  • 13

1 Answers1

0

Create a script for yesterday.. yesterday.sh

#Get the date month and date cut the necessary date 

ystd=$(date --date yesterday | cut -d' ' -f2,3) tdy=$(date --date today | cut -d' ' -f2,3)

#show the date yesterday Month and date 

echo ${ystd} #show the date today Month and date echo ${tdy}

#grep the date try checking the tdy since you may have no login yesterday 

last | grep "$tdy"

email it

  • 8 * * * /user/yesterday.sh | mail -s "Last Login Yesterday" me@example.net
jmazaredo
  • 202
  • 5
  • 13