最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

shell日志顏色處理及清理系統(tǒng)日志的方法

 更新時(shí)間:2018年09月27日 16:44:53   作者:一只漸行漸遠(yuǎn)的運(yùn)維狗  
這篇文章主要介紹了shell日志顏色處理及清理系統(tǒng)日志的方法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

記錄一下shell日志顏色處理

_COLORS=${BS_COLORS:-$(tput colors 2>/dev/null || echo 0)}
__detect_color_support() {
  # shellcheck disable=SC2181
  if [ $? -eq 0 ] && [ "$_COLORS" -gt 2 ]; then
    RC='\033[1;31m'
    GC='\033[1;32m'
    BC='\033[1;34m'
    YC='\033[1;33m'
    EC='\033[0m'
  else
    RC=""
    GC=""
    BC=""
    YC=""
    EC=""
  fi
}
__detect_color_support
echoerror() {
  printf "${RC} * ERROR${EC}: %s\\n" "$@" 1>&2;
}
echoinfo() {
  printf "${GC} * INFO${EC}: %s\\n" "$@";
}
echowarn() {
  printf "${YC} * WARN${EC}: %s\\n" "$@";
}

下面看下shell清理系統(tǒng)日志

1.設(shè)置日志峰值,到達(dá)則刪除
2.定時(shí)檢測(cè),crontab添加定時(shí)任務(wù)
3.后臺(tái)掛載 : ./xx.sh &

工作腳本:

#! /bin/sh
#日志目錄及限定大小
workdir="/var/*.log"
maxsize=100
#搜索最老文件,不加目錄默認(rèn)的本目錄里邊的文件 r倒序輸出 t時(shí)間 head -n1取第一行 awk命令括號(hào)$1位文件名 管道連接
oldfile(){
 oldfile=`ls $workdir -t 2>/dev/null| head -n1 | awk '{printf $1}'`
}
clear_old_log(){
 if [ ! $oldfile ]
 then
  #echo "日志不存在" 1>/dev/null
  return 0
 fi
  while true;
 do
  oldfile
  if [ ! $oldfile ]
  then
    return 0
  fi
  logsize=`du -ms $oldfile 2>/dev/null| awk '{printf $1}'` #m表示兆 k b
  if [ $logsize -gt $maxsize ]
  then
  str1="log"
  str2="err"
  if [[ $oldfile == *$str1* ]] 
  then
  pkill snake
  rm -rf $oldfile
   fi
   if [[ $oldfile == *$str2* ]]
   then
  service mysql restart
  pkill snake
  rm -rf $oldfile
  fi
  else
  break
  fi
 done
}
testing(){
 
 while true;
 do
  workdir="/var/*.log"
  oldfile 
   clear_old_log
   workdir="/var/lib/mysql/*.err"
   oldfile
   clear_old_log
  done
}
testing
定時(shí)任務(wù)腳本:
#! /bin/sh
#a=`pgrep -f test1.sh|wc -l`
#if [ $(ps -ef|grep test.sh|wc -l) -gt 1 ]
if test $(pgrep -f test.sh|wc -l) -ge 1
 then
 exit
fi
cd /home/zxd/
./test.sh
下邊這個(gè)帶有日志時(shí)間加時(shí)間戳及系統(tǒng)負(fù)載檢測(cè):
#! /bin/bash
strA="long string"
strB="string"
result=$(echo $strA | grep "${strB}")
if [[ "$result" != "" ]]
then
  echo "包含"
else
  echo "不包含"
fi
#日志目錄及限定大小
workdir="/var/*.log"
maxsize=100
#給文件加時(shí)間戳:函數(shù)里的變量必須在腳本函數(shù)后邊跟著,這里$1不是命令行跟的參數(shù),命令行的參數(shù)為腳本的$1
filetime(){
 a=$(date +%Y%m%d%H%M%S)
 A=$1.$(date +%Y%m%d%H%M%S)
 echo $A
}
filetime "/var/log"
#搜索最老文件,不加目錄默認(rèn)的本目錄里邊的文件 r倒序輸出 t時(shí)間 head -n1取第一行 awk命令括號(hào)$1位文件名 管道連接
oldfile(){
 oldfile=`ls $workdir -rt 2>/dev/null| head -n1 | awk '{printf $1}'`
}
clear_old_log(){
 if [ ! $oldfile ]
 then
  echo "日志不存在" 1>/dev/null
  return 0
 fi
  while true;
 do
  oldfile
  if [ ! $oldfile ]
  then
  echo "日志不存在" 1>/dev/null
   return 0
  fi
  logsize=`du -bs $oldfile 2>/dev/null| awk '{printf $1}'`
  if [ $logsize -gt $maxsize ]
  then
  str1="log"
  str2="err"
  if [[ $oldfile == *$str1* ]] 
  then
  pkill snake
  rm -rf $oldfile
   fi
   if [[ $oldfile == *$str2* ]]
   then
  service mysql restart
  pkill snake
  rm -rf $oldfile
   fi
  else
  break
  fi
 done
}
testing(){
 echo "run"
 while true;
 do
  oldfile 
   clear_old_log
   echo "222"
   workdir="/var/lib/mysql/libmaster.err"
   oldfile
   clear_old_log
  done
}
disk=`df |grep /dev/mapper/fedora-root | awk '{printf $5}' | sed 's/%//g'`
echo "磁盤已用:%$disk"
memtotal=`cat /proc/meminfo |grep MemTotal |awk '{printf $2}'`
memfree=`cat /proc/meminfo |grep MemFree |awk '{printf $2}'`
used=$((100- memfree*100/memtotal))
echo "內(nèi)存已用:%$used"
echo "exit"
testing

總結(jié)

以上所述是小編給大家介紹的shell日志顏色處理方法,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

  • 隱藏shell腳本內(nèi)容的工具?shc詳解

    隱藏shell腳本內(nèi)容的工具?shc詳解

    本文主要介紹了隱藏shell腳本內(nèi)容的工具?shc,?雖然它加密的安全性不高,但是我們平??梢园阉鳛橐粋€(gè)shell腳本代碼隱藏和混淆工具來(lái)使用,對(duì)shell腳本隱藏相關(guān)知識(shí)感興趣的朋友一起看看吧
    2021-11-11
  • shell腳本怎樣判斷文件是否存在

    shell腳本怎樣判斷文件是否存在

    這篇文章主要介紹了shell腳本怎樣判斷文件是否存在問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-06-06
  • 反彈shell的幾種姿勢(shì)小結(jié)

    反彈shell的幾種姿勢(shì)小結(jié)

    在滲透過(guò)程中,往往因?yàn)槎丝谙拗贫鵁o(wú)法直連目標(biāo)機(jī)器,此時(shí)需要通過(guò)反彈shell來(lái)獲取一個(gè)交互式shell,以便繼續(xù)深入,本文就介紹了幾種方法,感興趣的可以了解一下
    2021-07-07
  • 使用shell腳本分析網(wǎng)站日志統(tǒng)計(jì)PV、404、500等數(shù)據(jù)

    使用shell腳本分析網(wǎng)站日志統(tǒng)計(jì)PV、404、500等數(shù)據(jù)

    這篇文章主要介紹了使用shell腳本分析網(wǎng)站日志統(tǒng)計(jì)PV(瀏覽量)、404、500等數(shù)據(jù),用一個(gè)腳本來(lái)實(shí)現(xiàn),需要的朋友可以參考下
    2014-05-05
  • getopts解析shell腳本命令行參數(shù)的方法

    getopts解析shell腳本命令行參數(shù)的方法

    getpots是Shell命令行參數(shù)解析工具,旨在從Shell Script的命令行當(dāng)中解析參數(shù),這篇文章主要介紹了getopts解析shell腳本命令行參數(shù),需要的朋友可以參考下
    2023-01-01
  • shell一鍵部署Zabbix的實(shí)現(xiàn)步驟

    shell一鍵部署Zabbix的實(shí)現(xiàn)步驟

    本文主要介紹了shell一鍵部署Zabbix的實(shí)現(xiàn)步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2024-02-02
  • Linux 中wget命令詳細(xì)介紹

    Linux 中wget命令詳細(xì)介紹

    這篇文章主要介紹了Linux 中wget命令詳細(xì)介紹的相關(guān)資料,需要的朋友可以參考下
    2017-07-07
  • Shell中的循環(huán)語(yǔ)句for、while、until實(shí)例講解

    Shell中的循環(huán)語(yǔ)句for、while、until實(shí)例講解

    這篇文章主要介紹了Shell中的循環(huán)語(yǔ)句for、while、until實(shí)例講解,簡(jiǎn)單清晰明了,非常不錯(cuò)的教程,需要的朋友可以參考下
    2014-06-06
  • Shell調(diào)用curl實(shí)現(xiàn)IP歸屬地查詢的腳本

    Shell調(diào)用curl實(shí)現(xiàn)IP歸屬地查詢的腳本

    這篇文章主要介紹了Shell調(diào)用curl實(shí)現(xiàn)IP歸屬地查詢,文中給大家提到了查詢IP歸屬地的shell腳本,在批量查找數(shù)據(jù)的時(shí)候經(jīng)常會(huì)遇到,今天給大家分享出來(lái),需要的朋友可以參考下
    2021-07-07
  • Linux中文件的基本屬性介紹

    Linux中文件的基本屬性介紹

    這篇文章介紹了Linux中文件的基本屬性,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-05-05

最新評(píng)論

内黄县| 会昌县| 芒康县| 潮州市| 阳曲县| 桦南县| 鄂尔多斯市| 波密县| 靖安县| 桐乡市| 合肥市| 三亚市| 阜南县| 兴化市| 南通市| 平遥县| 上蔡县| 康乐县| 铜鼓县| 义马市| 子长县| 柘荣县| 汤阴县| 黔江区| 榆树市| 留坝县| 宜良县| 金沙县| 阳山县| 奉化市| 随州市| 洞头县| 任丘市| 黑山县| 唐河县| 延寿县| 通河县| 雷山县| 白水县| 同德县| 楚雄市|