update some content
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
"articleSection" : "post",
|
||||
"name" : "[筆記] 紀錄所有下過的指令、時間 \/ Log All commands with timestamp",
|
||||
"headline" : "[筆記] 紀錄所有下過的指令、時間 \/ Log All commands with timestamp",
|
||||
"description" : "\x3cp\x3e今天發生一件有點詭異的事情,本來應該要經過某個指令才會產生的檔案\x3c\/p\x3e\n\x3cp\x3e居然不知為何自己產生了,在我記憶中沒有去執行過那個指令\x3c\/p\x3e\n\x3cp\x3e翻了一下 bash_history ,裡面也只有下過哪些指令,沒有紀錄時間,完全沒有參考價值(攤手)\x3c\/p\x3e\n\x3cp\x3e所以翻了一下網路,至少把這兩台主要跑ansible的機器的log功能補上紀錄所有指令以及時間的部份\x3c\/p\x3e",
|
||||
"description" : "\u003cp\u003e今天發生一件有點詭異的事情,本來應該要經過某個指令才會產生的檔案\u003c\/p\u003e\n\u003cp\u003e居然不知為何自己產生了,在我記憶中沒有去執行過那個指令\u003c\/p\u003e\n\u003cp\u003e翻了一下 bash_history ,裡面也只有下過哪些指令,沒有紀錄時間,完全沒有參考價值(攤手)\u003c\/p\u003e\n\u003cp\u003e所以翻了一下網路,至少把這兩台主要跑ansible的機器的log功能補上紀錄所有指令以及時間的部份\u003c\/p\u003e",
|
||||
"inLanguage" : "en",
|
||||
"author" : "Eric Chang",
|
||||
"creator" : "Eric Chang",
|
||||
@@ -21,8 +21,8 @@
|
||||
"accountablePerson" : "Eric Chang",
|
||||
"copyrightHolder" : "Eric Chang",
|
||||
"copyrightYear" : "2019",
|
||||
"datePublished": "2019-04-23 15:08:36 \x2b0800 CST",
|
||||
"dateModified" : "2019-04-23 15:08:36 \x2b0800 CST",
|
||||
"datePublished": "2019-04-23 15:08:36 \u002b0800 CST",
|
||||
"dateModified" : "2019-04-23 15:08:36 \u002b0800 CST",
|
||||
"url" : "https:\/\/h.cowbay.org\/post\/log-all-bash-commands\/",
|
||||
"wordCount" : "205",
|
||||
"image" : "https://h.cowbay.orghttps://h.cowbay.org/images/post-default-11.jpg"",
|
||||
@@ -45,9 +45,9 @@
|
||||
|
||||
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
|
||||
|
||||
<link href="https://h.cowbay.org/css/style.css?v=1632901489" rel="stylesheet" id="theme-stylesheet" type='text/css' media='all'>
|
||||
<link href="https://h.cowbay.org/css/style.css?v=1634607506" rel="stylesheet" id="theme-stylesheet" type='text/css' media='all'>
|
||||
|
||||
<link href="https://h.cowbay.org/css/custom.css?v=1632901489" rel="stylesheet" type='text/css' media='all'>
|
||||
<link href="https://h.cowbay.org/css/custom.css?v=1634607506" rel="stylesheet" type='text/css' media='all'>
|
||||
<link rel="shortcut icon" href="https://h.cowbay.org/img/favicon.ico" type="image/x-icon">
|
||||
<link rel="icon" href="https://h.cowbay.org/img/favicon.ico" type="image/x-icon">
|
||||
|
||||
@@ -314,9 +314,9 @@ if (!doNotTrack) {
|
||||
<p>所以先用minion(管理用的帳戶)登入後</p>
|
||||
<p>先編輯 ~/.bashrc
|
||||
加入</p>
|
||||
<pre><code>export PROMPT_COMMAND='RETRN_VAL=$?;logger -p local6.debug "$(whoami) [$$]: $(history 1 | sed "s/^[ ]*[0-9]\+[ ]*//" ) [$RETRN_VAL]"'
|
||||
<pre tabindex="0"><code>export PROMPT_COMMAND='RETRN_VAL=$?;logger -p local6.debug "$(whoami) [$$]: $(history 1 | sed "s/^[ ]*[0-9]\+[ ]*//" ) [$RETRN_VAL]"'
|
||||
</code></pre><p>因為這邊用到syslog 的 local6,所以要跟著修改 syslog的設定</p>
|
||||
<pre><code>sudo vim /etc/rsyslog.d/bash.conf
|
||||
<pre tabindex="0"><code>sudo vim /etc/rsyslog.d/bash.conf
|
||||
|
||||
加入這行
|
||||
|
||||
@@ -332,7 +332,7 @@ sudo vim /etc/logrotate.d/rsyslog
|
||||
|
||||
sudo service rsyslog restart
|
||||
</code></pre><p>用 minion 登出登入後,就可以看到所有指令都被完整的紀錄下來了</p>
|
||||
<pre><code>sudo cat /var/log/commands.log
|
||||
<pre tabindex="0"><code>sudo cat /var/log/commands.log
|
||||
|
||||
2019-04-23 15:18:48 [minion@hqs010 ~]$ sudo cat /var/log/commands.log
|
||||
Apr 23 15:06:51 hqs010 minion: minion [30832]: [0]
|
||||
@@ -636,7 +636,7 @@ title="pinterest icon"></i>
|
||||
</div>
|
||||
<script src="https://h.cowbay.org/js/jquery.min.js"></script>
|
||||
<script src="https://h.cowbay.org/js/jquerymigrate.js"></script>
|
||||
<script src="https://h.cowbay.org/js/production.min.js?v=1632901489"></script>
|
||||
<script src="https://h.cowbay.org/js/production.min.js?v=1634607506"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user