Last active
April 15, 2022 12:02
-
-
Save peytonyip/77365966150dac573963c04dc731683c to your computer and use it in GitHub Desktop.
[一些 shell 脚本] #shell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| datetime=$(date +%Y%m%d%H%M%S) | |
| dbs=("chatbot" "chatbot_kg" "chatbot_v2" "chatbot_walle" "nlp_asr_tts_ws" "quality_check" "sound" "walle_deploy") | |
| #dbs=("walle_deploy") | |
| for ((i=0;i<${#dbs[@]};i++)) | |
| do | |
| cd /home/work/workplace/backup || exit | |
| db=${dbs[$i]} | |
| /home/work/workplace/mariadb-10.4.8/bin/mysqldump -ubackup_ro -pbackup_ro -h172.18.36.235 --lock-tables=false --quick --databases "${db}" > "${db}-${datetime}.sql" | |
| done | |
| find /home/work/workplace/backup -mtime +7 -name "*.*" -exec rm -rf {} \; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash - | |
| # top -n 参数指定运行次数,1代表运行一次即停止,不再等待top数据更新,使用awk指定分割符,提取数据 | |
| cpu_us=`top -n 1 | grep 'Cpu(s)' | awk -F'[" "%]+' '{print $2}'` | |
| cpu_sy=`top -n 1 | grep 'Cpu(s)' | awk -F'[" "%]+' '{print $4}'` | |
| cpu_idle=`top -n 1 | grep 'Cpu(s)' | awk -F'[" "%]+' '{print $8}'` | |
| # 默认bash shell不能直接运算小数点,所以需要借助bc | |
| # bc命令是一种支持任意精度的交互执行的计算器语言。 | |
| # 常见用法 echo "1.23*5" | bc | |
| cpu_sum=$(echo "$cpu_us+$cpu_sy"|bc) | |
| echo "CPU_SUM: $cpu_sum%" | |
| echo "CPU_Idle: ${cpu_idle}%" | |
| #超过阀值即发送邮件 | |
| if [ $cpu_sum -ge 90 ];then | |
| echo "CPU utilization $cpu_sum" | mail -s "cpu status warning." [email protected] | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment