当前位置:网站首页>如何不耍流氓的做运维之-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
边栏推荐
猜你喜欢
IO process thread -> thread -> day5
How to prepare for the test interface test data
Talking about GIS Data (5) - Geographic Coordinate System
High availability, two locations and three centers
CAD有生僻字如何打出来、如何提交软件相关问题或建议?
接口管理工具YApi怎么用?颜值高、易管理、超好用
Bubble sort in c language structure
tag单调栈-单调栈预备知识-lt.739. 每日温度
Exception(异常) 和 Error(错误)区别解析
shell script loop statement
随机推荐
1058 选择题 (20 分)(C语言)
UV decomposition of biotin - PEG2 - azide | CAS: 1192802-98-4 biotin connectors
生活原则。
安装IIS服务(Internet信息服务(Internet Information Services,简写IIS,互联网信息服务)
DFS对剪枝的补充
反射注解基础
Exception (abnormal) and Error (error) difference analysis
测试人员的价值体现在哪里
接口测试框架实战(四)| 搞定 Schema 断言
Apache DolphinScheduler版本2.0.5分布式集群的安装
shell script loop statement
Bubble sort in c language structure
【Harmony OS】【ARK UI】ets use startAbility or startAbilityForResult to invoke Ability
在树莓派上搭建属于自己的网页(2)
Interface testing framework of actual combat (2) | interface request assertion
c语言结构体中的冒泡排序
closures in js
Interface testing framework combat (3) | JSON request and response assertion
typescript43-类型兼容性说明
1. 两数之和