如何從使用AWK的wtmp文件的開頭每天獲取登錄次數? 我想過使用關聯數組,但我不知道如何實現它在AWK ..使用Shell腳本和AWK在Linux上登錄的次數
myscript.sh
#!/bin/bash
awk 'BEGIN{numberoflogins=0}
#code goes here'
的last
命令的輸出:
[[email protected] Documents]$ last
fnorbert tty2 /dev/tty2 Mon Apr 24 13:25 still logged in
reboot system boot 4.8.6-300.fc25.x Mon Apr 24 16:25 still running
reboot system boot 4.8.6-300.fc25.x Mon Apr 24 13:42 still running
fnorbert tty2 /dev/tty2 Fri Apr 21 16:14 - 21:56 (05:42)
reboot system boot 4.8.6-300.fc25.x Fri Apr 21 19:13 - 21:56 (02:43)
fnorbert tty2 /dev/tty2 Tue Apr 4 08:31 - 10:02 (01:30)
reboot system boot 4.8.6-300.fc25.x Tue Apr 4 10:30 - 10:02 (00:-27)
fnorbert tty2 /dev/tty2 Tue Apr 4 08:14 - 08:26 (00:11)
reboot system boot 4.8.6-300.fc25.x Tue Apr 4 10:13 - 08:26 (-1:-47)
wtmp begins Mon Mar 6 09:39:43 2017
外殼腳本的輸出應爲:
Apr 4: 4
Apr 21: 2
Apr 24: 3
,使用關聯數組,如果有可能
爲了使這個問題自包含的,你應該張貼的更多信息:什麼是'wtmp'內容?它的位置的路徑是什麼? –
你可以先給我們展示你的輸入文件 – Inian
對不起,我說的不夠清楚。我的意思是來自** last **命令輸出的最後一行,其中說:「wtmp開始於2017年3月6日星期一09:39:43」。我不知道這個文件在哪裏可以找到,只是我聽說過它,我認爲這將是有益的,如果我提到它。 –