第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

History- Linux下定制個(gè)性化history記錄

標(biāo)簽:
Linux

导语

作为Linux管理员,在出现问题的时候,有时候想反查过去某段时间内 那个用户在什么时间执行过什么命令。这个时候就需要用到Linux下面的history功能


说明

作为管理员,希望能将所有的history记录保存自己方便控制的运维主机上面方便同意管理和查阅,不同主机的记录按主机ip分目录存放

管理员可以查阅所有的,但是普通用户只允许创建查阅属于自己的history记录我呢见


脚本

#!/usr/bin/env bash 
currentip=$(/usr/sbin/ifconfig |grep 'inet ' |grep -v '127.0.0.1' |awk '{print $2}')
historyPath="/devOps/backup/history/"## 不同主机的记录按IP创建不同的目录存放if [ ! -d ${historyPath}${currentip} ] 
then
    mkdir -p ${historyPath}${currentip}
    chmod -R 777 ${historyPath}${currentip}
    chmod a+t ${historyPath}${currentip}fi## history setting ## 区分管理root和普通用户,普通用户只读if [ $UID -ge 500 ]then
    readonly HISTFILE=${historyPath}${currentip}/$USER-$UID.log
    readonly HISTFILESIZE=50000    readonly HISTSIZE=10000    readonly HISTTIMEFORMAT="%F %T `who am i |awk '{print $1}'` `whoami` "
    readonly HISTCONTROL=ignoredups    shopt -s histappend    readonly PROMPT_COMMAND="history -a"else
    HISTFILE=${historyPath}${currentip}/$USER-$UID.log
    HISTFILESIZE=50000
    HISTSIZE=10000
    HISTTIMEFORMAT="%F %T `who am i |awk '{print $1}'` `whoami` "
    HISTCONTROL=ignoredups    shopt -s histappend
    PROMPT_COMMAND="history -a"fi

实际效果

 1588  2016-09-12 11:23:09 root root tail -f /usr/local/tomcat/logs/dataLog/define.log  |grep MasterBGirlSayHiBoy
 1589  2016-09-12 11:38:00 root root cat /usr/local/tomcat/logs/dataLog/define.log  |grep sendTopicMsg
 1590  2016-09-12 11:39:22 root root cat /usr/local/tomcat/logs/dataLog/define.log  |grep sendTopicMsg |grep '"billing":"2"'
 1591  2016-09-12 11:39:26 root root cat /usr/local/tomcat/logs/dataLog/define.log  |grep sendTopicMsg |grep '"billing":"5"'
 1592  2016-09-12 11:59:27 root root cat /etc/profile.d/history.sh

附加知识点

who am i && whoami



作者:全栈运维
链接:https://www.jianshu.com/p/f5d94cf4e79a

點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評(píng)論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評(píng)論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消