jmazaredo Asked: 2016-04-19 19:37:49 +0800 CST2016-04-19 19:37:49 +0800 CST 2016-04-19 19:37:49 +0800 CST Linux last login get the logins yesterday and email it the next day or specific time via crontab 772 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. cron login last 1 Answers Voted jmazaredo 2016-04-19T19:37:49+08:002016-04-19T19:37:49+08:00 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" [email protected]
Create a script for yesterday.. yesterday.sh
ystd=$(date --date yesterday | cut -d' ' -f2,3) tdy=$(date --date today | cut -d' ' -f2,3)
echo ${ystd} #show the date today Month and date echo ${tdy}
last | grep "$tdy"
email it