
我知道該date -s <STRING>
命令設定字串描述的時間STRING
。
我想要的是每當使用上面的命令將時間設定到文件中時就將其記錄下來/tmp/log/user.log
。
在我的 Linux 發行版中,日誌記錄是由syslog-ng
.我已經有一些日誌進入/tmp/log/user.log
.
這是我係統中用於登入的 /etc/syslog-ng/syslog-ng.conf 的內容/tmp/log/user.log
destination d_notice { file("/tmp/log/user.log");};
filter f_filter10 { level(notice) and not facility(mail,authpriv,cron); };
log { source(s_sys); filter(f_filter10); destination(d_notice); };
我該怎麼做才能讓date -s
指令也登入到/tmp/log/user.log
答案1
預設不會記錄日期更改,至少在 Debian 上不會。
最簡單的選擇是將 /bin/date 替換為包裝器,該包裝器使用logger
然後調用真正的 /bin/date 可執行檔來列印日誌訊息,例如
mv /bin/date /bin/date.real
cat << 'EOF' >/bin/date
#!/bin/bash
logger -p user.notice "date run by $UID: $*"
/bin/date.real
EOF
chmod +x /bin/date
除此之外,我知道網路安全允許您記錄對系統時間的任何變更。它需要編譯一個自訂內核。