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

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

【九月打卡】第18天 一課玩轉(zhuǎn)自動(dòng)化運(yùn)維全流程,輕松應(yīng)對(duì)自動(dòng)化運(yùn)維崗

课程章节: 2章 shell编程基础:2-19 Shell脚本实战(二)(课程链接:https://coding.imooc.com/lesson/549.html#mid=50193

主讲老师: 沈奇才

课程内容:shell编程实战与Linux运维基础--初始shell编程

课程收获:

日志备份实战,应用于多机器或集群运维场景

#! /bin/bash

# 日志压缩

LOG_DIR=logs

[[ -d "$LOG_DIR" ]]  || mkdir $LOG_DIR

cd $LOG_DIR

log_out() {

   log_path="compress.log"

   echo $1  >> $log_path

}

# 按照 101230   每10秒生成日志文件

produce_log_files() {

   while ls > /dev/null

   do

       let "host_count = $RANDOM % 7 + 2"   # 2-8

       now_time=$(date "+%H%M%S")

       declare -a host_arr

       for i in `seq 0 $host_count`   # 5  0-5

       do

           host_arr[$i]="10.83.26.`expr $i + 10`"    # 10-15

       done

       

       for host in "${host_arr[@]}"

       do

           log_out "生成日志文件: ${host}_${now_time}.access.log"

           touch ${host}_${now_time}.access.log

       done

       sleep 10

   done

}

compress_log_files() {

   while  ls > /dev/null

   do

       sleep 1

       compress_time=$(find . -name "*.access.log" -exec basename {} \; | awk -F_ '{print $2}' | awk -F. '{print $1}' | sort -r | uniq | awk 'NR==1{print}')

       if [ -z "$compress_time" ]; then

           log_out "当前没有日志文件要压缩"

           continue

       fi

       log_out "压缩${compress_time}文件..."

       find . -name "*${compress_time}.access.log" | xargs tar -czPf log_compress_${compress_time}.tar.gz

       if [ $? -eq 0 ] && [ -e "log_compress_${compress_time}.tar.gz" ]; then

           find . -name "*${compress_time}.access.log" -exec rm -f {} \;

       fi

       log_out "压缩${compress_time}文件完成..."

   done

}

produce_log_files  & ##放入后台查询

compress_log_files  & ##放入后台查询

对于集群的运维,除了使用遍历,还可以通过创建配置文件host.cfg,将所有需要运维的主机ip写进去,程序读取配置文件。

https://img1.sycdn.imooc.com//632bc9d50001a2ca19200913.jpghttps://img1.sycdn.imooc.com//632bc9ba0001fa1219200913.jpg

https://img1.sycdn.imooc.com//632bc9e800018f2619200913.jpg

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

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

評(píng)論

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

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

100積分直接送

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

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

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

購(gòu)課補(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
提交
取消