Linux使用者登入記錄分析指令碼

mrhutoo發表於2013-10-28
#!/bin/bash
TDATE=`date +"%b %-d"`
YDATE=`date -d last-day +"%b %-d"`
last root|grep pts|grep -v still|awk '{print $1","$3","$5,$6","$7","$9","$10}'|grep "$TDATE">last
last root|grep pts|grep -v still|awk '{print $1","$3","$5,$6","$7","$9","$10}'|grep "$YDATE">>last
STDATE=`date -d "$TDATE" +%Y%m%d`
SYDATE=`date -d "$YDATE" +%Y%m%d`
sed -e "s/$TDATE/$STDATE/" last|sed -e "s/$YDATE/$SYDATE/">lastb
 
TDATE:today
YDATE:yesterday
STDATE:String format today
SYDATE:String format yesterday
lastb:result

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24955184/viewspace-775150/,如需轉載,請註明出處,否則將追究法律責任。

相關文章