1 parent a4c06e5 commit 9df7b4cCopy full SHA for 9df7b4c
1 file changed
collectroothistory.sh
@@ -0,0 +1,26 @@
1
+#!/bin/bash
2
+## Collect Root Commands History
3
+
4
+# Mailing List
5
+MAILLIST="YOUREMAIL@DOMAIN"
6
7
+# Log path
8
+AUDLOG="/rootcommands"
9
10
+cp /root/.bash_history /tmp/history
11
+sed -i 's/#//g' /tmp/history
12
+for i in `cat /tmp/history |grep ^[0-9]`
13
+do
14
+CONVT=`date -d @$i`
15
+sed -i "s/$i/$CONVT/g" /tmp/history
16
+done
17
18
+sed -i 'N;s/\n/ /' /tmp/history
19
+sleep 10
20
21
+/bin/touch ${AUDLOG}$HOSTNAME-root-hist.log.`date +%h%d%y`
22
+/bin/grep "$DATE" /tmp/history > ${AUDLOG}$HOSTNAME-root-hist.log.`date +%h%d%y`
23
+/bin/chmod 0440 ${AUDLOG}$HOSTNAME-root-hist.log.`date +%h%d%y`
24
25
+# Mail notification
26
+/bin/cat ${AUDLOG}$HOSTNAME-root-hist.log.`date +%h%d%y` |mail -s "HOST: $HOSTNAME - `whoami` Daily root Commands Log" ${MAILLIST}
0 commit comments