当前位置:网站首页>如何不耍流氓的做运维之-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
边栏推荐
- Interface test framework combat (1) | Requests and interface request construction
- MOSN 反向通道详解
- typescript47-函数之间的类型兼容性
- Gradle的安装配置
- [Developers must see] [push kit] Collection of typical problems of push service service 2
- Concepts and Methods of Exploratory Testing
- 用户密码加密工具
- 接口测试框架实战(二)| 接口请求断言
- DFS对剪枝的补充
- Harmony OS Date ano UI 】 【 】 the basic operation
猜你喜欢
typescript43-类型兼容性说明
【Harmony OS】【ArkUI】ets开发 基础页面布局与数据连接
Jmeter 模拟多用户登录的两种方法
CAD有生僻字如何打出来、如何提交软件相关问题或建议?
Common lipophilic cell membrane dyes DiO, Dil, DiR, Did spectrograms and experimental procedures
Peptides mediated PEG DSPE of phospholipids, targeted functional materials - PEG - RGD/TAT/NGR/APRPG
typescript46-函数之间的类型兼容性
【Harmony OS】【ARK UI】Date 基本操作
Bubble sort in c language structure
【Biotin Azide|cas:908007-17-0】Price_Manufacturer
随机推荐
2022暑假牛客多校联赛第一场
Talking about GIS Data (6) - Projected Coordinate System
反射注解基础
生活原则。
Windows 安装PostgreSQL
User password encryption tool
Modified BiotinDIAZO-Biotin-PEG3-DBCO|diazo-biotin-tripolyethylene glycol-diphenylcyclooctyne
[Fine talk] Using native js to implement todolist
建造者模式(Builder Pattern)
WebSocket的实际应用
Lambda表达式案例
【HMS core】【Ads Kit】Huawei Advertising——Overseas applications are tested in China. Official advertisements cannot be displayed
idea uses @Autowired annotation to explain the reasons and solutions
js implements a bind function
MCM box model modeling method and source analysis of atmospheric O3
Interface testing framework of actual combat (2) | interface request assertion
Two ways to simulate multi-user login in Jmeter
js garbage collection mechanism
JS bottom handwriting
用户密码加密工具