vim func_global.sh
#!/usr/bin/env bash
#################################################################
#
# 用途:全局函数
#
# 日期:2022-03-25
#
# 作者:moyuanbo
#
#################################################################
source /data/ops/global/variable_global.sh
function current_time() {
date +"%Y%m%d %H:%M:%S"
}
function shell_lock() {
[[ -d tmp ]] || mkdir tmp
[[ -f tmp/shell.lock ]] && \
echo_error "脚本正在运行,请删除锁文件(tmp/shell.lock)之后再执行该脚本,删除前请确认是否只有本人在操作" && \
exit
touch tmp/shell.lock
}
function shell_unlock() {
[[ -f tmp/shell.lock ]] && \rm -f tmp/shell.lock
}
function echo_grey() {
echo -e "\e[30;1m[$(current_time)] ${1}\e[0m"
}
function error_log() {
echo -e "\e[31;1m[$(current_time)] ${1}\e[0m" | tee -a ${2}
}
function echo_error() {
echo -e "\e[31;1m[$(current_time)] ${1}\e[0m"
}
function succes_log() {
echo -e "\e[32;1m[$(current_time)] ${1}\e[0m" | tee -a ${2}
}
function echo_succes() {
echo -e "\e[32;1m[$(current_time)] ${1}\e[0m"
}
function echo_print() {
echo -e "\e[33;1m[$(current_time)] ${1}\e[0m"
}
function echo_blue() {
echo -e "\e[34;1m[$(current_time)] ${1}\e[0m"
}
function echo_pink() {
echo -e "\e[35;1m[$(current_time)] ${1}\e[0m"
}
function echo_purple() {
echo -e "\e[36;1m[$(current_time)] ${1}\e[0m"
}
function echo_white() {
echo -e "\e[37;1m[$(current_time)] ${1}\e[0m"
}
function error_exit() {
echo_error "${1}"
shell_unlock
exit 1
}
function executed() {
echo_succes "${1}已执行"
echo_print "如果确定要重新执行请删掉文件(${2}),重新执行本脚本"
}
function inspect_execute() {
grep "${1}执行完成" ${2} &> /dev/null
if [[ $? -eq 0 ]] ; then
executed ${1} ${2}
return 0
else
return 255
fi
}
function execute_end() {
echo "${1}执行完成" >> ${2}
}
function clear_execute() {
[[ -s ${1} ]] && mv ${1} ${1}_$(date +"%Y%m%d_%H%M%S")
find logs/ -type f -mtime +2 | xargs rm -f
}