当前位置:网站首页>如何不耍流氓的做运维之-SHELL脚本
如何不耍流氓的做运维之-SHELL脚本
2022-08-03 05:10:00 【lhorse003】
2 个评论
举一个例子:
#!/bin/bash
#***************************************************************************
# *
# * @file:pid_run.sh
# * @author:Luolired
# * @date:2016-01-05 16:26
# * @version 0.5
# * @description: 节点提升为master调用的脚本
# * 1.脚本标准化 notify_master "/etc/keepalived/scripts/pid_run.sh"
# * @Copyright (c) 007ka all right reserved
# * @updatelog:
# * 1.更新程序标准化逻辑性
# * 2.优化日志的输出
# * 3.增加同步锁状态标识,用以区分同步开启
# * 4.增加Keepalived主备切换功能开启锁,用以初始化启动抢占操作多开或Stop原有业务
#**************************************************************************/
export LANG=zh_CN.GBK
1.4.1 结果输出函数模块
### Print error messges eg: _err "This is error"
function _err()
{
#echo -e "\033[1;31m[ERROR] [email protected]\033[0m" >&2
echo -e "\033[1;31m[ERROR] [email protected]\033[0m"
}
### Print notice messages eg: _info "This is Info"
function _info()
{
#echo -e "\033[1;32m[Info] [email protected]\033[0m" >&2
echo -e "\033[1;32m[Info] [email protected]\033[0m"
}
1.4.2 日志输出函数模块
###LOG_PATH
###程序运行all日志输出路径
g_s_LOG_PATH=/var/applog/${G_LOG_FILE}
mkdir -p $g_s_LOG_PATH
g_s_LOGDATE=`date +"%F"`
#执行脚本生成的日志
g_s_LOGFILE="${g_s_LOG_PATH}/pid_run.${g_s_LOGDATE}.log"
### LOG to file eg:g_fn_LOG "Test"
g_fn_LOG()
{
s_Ddate=`date +"%F %H:%M:%S"`
echo "[$s_Ddate] $*" >> $g_s_LOGFILE
}
1.4.3 flock锁函数模块
### Add flock Avoid more open program
function _lock()
{
flock -n 3
[ $? -eq 1 ] && { _err "Fault $(basename $0) is Already in Runing,Plesase Waiting....^_^ GoodBye!!!"; exit; }
_info "$(basename $0) Current Pid is:$$"
_log "$(basename $0) Current Pid is:$$"
sleep 50
} 3<>/tmp/$(basename $0 | awk -F. 'BEGIN{OFS="."};{NF=NF-1;print $0}').lock
function main()
{
_lock
}
#main
main
边栏推荐
- 1094 谷歌的招聘 (20 分)
- 接口测试框架实战(四)| 搞定 Schema 断言
- unity2D横板游戏教程6-敌人AI以及受击动画
- IO process thread -> thread -> day5
- 2022/08/02 Study Notes (day22) Multithreading
- 接口测试 Mock 实战(二) | 结合 jq 完成批量化的手工 Mock
- [Developers must see] [push kit] Collection of typical problems of push service service 2
- 技术分享 | 接口自动化测试中如何对xml 格式做断言验证?
- MCM box model modeling method and source analysis of atmospheric O3
- 1069 微博转发抽奖 (20 分)(C语言)
猜你喜欢

Talking about GIS Data (6) - Projected Coordinate System

【Harmony OS】【FAQ】Hongmeng Questions Collection 1

2022/08/02 学习笔记 (day22) 多线程

Install IIS services (Internet Information Services (Internet Information Services, abbreviated IIS, Internet Information Services)

Windows 安装PostgreSQL

idea uses @Autowired annotation to explain the reasons and solutions

CAD有生僻字如何打出来、如何提交软件相关问题或建议?

Where is the value of testers

Two ways to simulate multi-user login in Jmeter

接口和抽象
随机推荐
High availability, two locations and three centers
13.
lt.647. Palindromic substring + lt.516. Longest palindrome subsequence Harmony OS ets ArkUI 】 【 】 the development basic page layout and data connection
WebSocket的实际应用
Get the Ip tool class
接口测试框架实战(三)| JSON 请求与响应断言
探索性测试的概念及方法
数字孪生园区场景中的坐标知识
WinForm的控件二次开发
Presto installation and deployment tutorial
【 Harmony OS 】 【 ano UI 】 lightweight data storage
User password verification
JS bottom handwriting
shell脚本循环语句
Flink状态
Modified BiotinDIAZO-Biotin-PEG3-DBCO|diazo-biotin-tripolyethylene glycol-diphenylcyclooctyne
JDBC与连接池
Object类与常用API
Interface test practice | Detailed explanation of the difference between GET / POST requests
Kotlin-Flow common encapsulation class: the use of StateFlow




