{"id":3159,"date":"2012-06-25T17:34:00","date_gmt":"2012-06-25T09:34:00","guid":{"rendered":"http:\/\/jpuyy.com\/?p=3159"},"modified":"2012-11-14T11:12:50","modified_gmt":"2012-11-14T03:12:50","slug":"linux-log-user-command-history","status":"publish","type":"post","link":"https:\/\/jpuyy.com\/?p=3159","title":{"rendered":"\u6309\u65f6\u6309\u767b\u5f55IP\u8bb0\u5f55Linux\u6240\u6709\u7528\u6237\u64cd\u4f5c\u65e5\u5fd7\u7684\u65b9\u6cd5"},"content":{"rendered":"<p>\u8f6c\u81ea\uff1ahttp:\/\/www.ha97.com\/4733.html<\/p>\n<p>PS\uff1aLinux\u7528\u6237\u64cd\u4f5c\u8bb0\u5f55\u4e00\u822c\u901a\u8fc7\u547d\u4ee4history\u6765\u67e5\u770b\u5386\u53f2\u8bb0\u5f55\uff0c\u4f46\u662f\u5982\u679c\u56e0\u4e3a\u67d0\u4eba\u8bef\u64cd\u4f5c\u4e86\u5220\u9664\u4e86\u91cd\u8981\u7684\u6570\u636e\uff0c\u8fd9\u79cd\u60c5\u51b5\u4e0bhistory\u547d\u4ee4\u5c31\u4e0d\u4f1a\u6709\u4ec0\u4e48\u4f5c\u7528\u4e86\u3002\u4ee5\u4e0b\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u901a\u8fc7\u8bb0\u5f55\u767b\u9646IP\u5730\u5740\u548c\u6240\u6709\u7528\u6237\u767b\u5f55\u6240\u64cd\u4f5c\u7684\u65e5\u5fd7\u8bb0\u5f55\uff01<\/p>\n<p>\u5728\/etc\/profile\u914d\u7f6e\u6587\u4ef6\u7684\u672b\u5c3e\u52a0\u5165\u4ee5\u4e0b\u811a\u672c\u4ee3\u7801\u5c31\u53ef\u4ee5\u5b9e\u73b0<\/p>\n<pre>#PS1=\"`whoami`@`hostname`:\"'[$PWD]'\r\nhistory\r\nUSER_IP=`who -u am i 2&gt;\/dev\/null| awk '{print $NF}'|sed -e 's\/[()]\/\/g'`\r\nif [ \"$USER_IP\" = \"\" ]\r\nthen\r\nUSER_IP=`hostname`\r\nfi\r\nif [ ! -d \/tmp\/history ]\r\nthen\r\nmkdir \/tmp\/history\r\nchmod 777 \/tmp\/history\r\nfi\r\nif [ ! -d \/tmp\/history\/${LOGNAME} ]\r\nthen\r\nmkdir \/tmp\/history\/${LOGNAME}\r\nchmod 300 \/tmp\/history\/${LOGNAME}\r\nfi\r\nexport HISTSIZE=4096\r\nDT=`date +\"%Y%m%d_%H%M%S\"`\r\nexport HISTFILE=\"\/tmp\/history\/${LOGNAME}\/${USER_IP} history.$DT\"\r\nchmod 600 \/tmp\/history\/${LOGNAME}\/*history* 2&gt;\/dev\/null<\/pre>\n<p>\u901a\u8fc7\u4e0a\u9762\u7684\u4ee3\u7801\u53ef\u4ee5\u770b\u51fa\u6765\uff0c\u5728\u7cfb\u7edf\u7684\/tmp\u65b0\u5efa\u4e2ahistory\u76ee\u5f55\uff08\u8fd9\u4e2a\u76ee\u5f55\u53ef\u4ee5\u81ea\u5b9a\u4e49\uff09\uff0c\u5728\u76ee\u5f55\u4e2d\u8bb0\u5f55\u4e86\u6240\u6709\u7684\u767b\u9646\u8fc7\u7cfb\u7edf\u7684\u7528\u6237\u548cIP\u5730\u5740\uff0c\u8fd9\u4e5f\u662f\u76d1\u6d4b\u7cfb\u7edf\u5b89\u5168\u7684\u65b9\u6cd5\u4e4b\u4e00\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8f6c\u81ea\uff1ahttp:\/\/www.ha97.com\/4733.html PS\uff1aLinux\u7528\u6237\u64cd\u4f5c\u8bb0\u5f55\u4e00\u822c\u901a\u8fc7\u547d\u4ee4history\u6765\u67e5\u770b\u5386\u53f2\u8bb0\u5f55\uff0c\u4f46\u662f\u5982\u679c\u56e0\u4e3a\u67d0\u4eba\u8bef\u64cd\u4f5c\u4e86\u5220\u9664\u4e86\u91cd\u8981\u7684\u6570\u636e\uff0c\u8fd9\u79cd\u60c5\u51b5\u4e0bhistory\u547d\u4ee4\u5c31\u4e0d\u4f1a\u6709\u4ec0\u4e48\u4f5c\u7528\u4e86\u3002\u4ee5\u4e0b\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u901a\u8fc7\u8bb0\u5f55\u767b\u9646IP\u5730\u5740\u548c\u6240\u6709\u7528\u6237\u767b\u5f55\u6240\u64cd\u4f5c\u7684\u65e5\u5fd7\u8bb0\u5f55\uff01 \u5728\/etc\/profile\u914d\u7f6e\u6587\u4ef6\u7684\u672b\u5c3e\u52a0\u5165\u4ee5\u4e0b\u811a\u672c\u4ee3\u7801\u5c31\u53ef\u4ee5\u5b9e\u73b0 #PS1=&#8221;`whoami`@`hostname`:&#8221;&#8216;[$PWD]&#8217; history USER_IP=`who -u am i 2&gt;\/dev\/null| awk &#8216;{print $NF}&#8217;|sed -e &#8216;s\/[()]\/\/g&#8217;` if [ &#8220;$USER_IP&#8221; = &#8220;&#8221; ] then USER_IP=`hostname` fi if [ ! -d \/tmp\/history ] then mkdir \/tmp\/history chmod 777 \/tmp\/history fi if [ ! -d \/tmp\/history\/${LOGNAME} ] then mkdir \/tmp\/history\/${LOGNAME} chmod 300 \/tmp\/history\/${LOGNAME} fi export HISTSIZE=4096 DT=`date +&#8221;%Y%m%d_%H%M%S&#8221;` export [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-3159","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/3159","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3159"}],"version-history":[{"count":4,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/3159\/revisions"}],"predecessor-version":[{"id":4220,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/3159\/revisions\/4220"}],"wp:attachment":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3159"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3159"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3159"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}