shell脚本颜色配置

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
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值