当前位置:网站首页>如何不耍流氓的做运维之-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
边栏推荐
猜你喜欢

typescript39-class类的可见修饰符

Two ways to simulate multi-user login in Jmeter

Tributyl-mercaptophosphane "tBuBrettPhos Pd(allyl)" OTf), 1798782-17-8

高可用 两地三中心

MCM box model modeling method and source analysis of atmospheric O3

【Harmony OS】【ArkUI】ets开发 图形与动画绘制

typescript40-class类的保护修饰符

【Biotin Azide|cas:908007-17-0】Price_Manufacturer

Alienware上线首个数字时装AR试穿体验

UV decomposition of biotin - PEG2 - azide | CAS: 1192802-98-4 biotin connectors
随机推荐
设计模式——组合模式、享元模式(Integer缓存)(结构型模式)
集合框架知识
[Fine talk] Using native js to implement todolist
Peptides mediated PEG DSPE of phospholipids, targeted functional materials - PEG - RGD/TAT/NGR/APRPG
GIS数据漫谈(六)— 投影坐标系统
Gradle的安装配置
【HMS core】【Ads Kit】华为广告——海外应用在国内测试正式广告无法展示
Two ways to simulate multi-user login in Jmeter
【Harmony OS】【ARK UI】ETS 上下文基本操作
Super handy drawing tool is recommended
背压机制
2. 两数相加
WebSocket的实际应用
User password encryption tool
阿里云对象存储oss私有桶生成链接
shell script loop statement
Windows 安装PostgreSQL
接口测试如何准备测试数据
typescript47-函数之间的类型兼容性
Bubble sort in c language structure




