#!/bin/bash

LOG_RED=`tput setaf 1`
LOG_GREEN=`tput setaf 2`
LOG_RESET=`tput sgr0`
LOG_FILE=
function log_info ()
{

DATE_N=`date "+%Y-%m-%d %H:%M:%S"`
USER_N=`whoami`
echo "${DATE_N} ${USER_N} execute $0 [INFO] [email protected]" >> ${LOG_FILE} #执行成功日志打印路径

}

function log_error ()
{
DATE_N=`date "+%Y-%m-%d %H:%M:%S"`
USER_N=`whoami`
echo -e "\033[41;37m ${DATE_N} ${USER_N} execute $0 [ERROR] [email protected] \033[0m"  >> ${LOG_FILE} #执行失败日志打印路径

}

function fn_log ()  {
if [  $? -eq 0  ];then
        log_info "[email protected] sucessed."
        #echo -e "\033[32m [email protected] sucessed. \033[0m"
        echo ${LOG_GREEN} [email protected] sucessed.${LOG_RESET}
else
        log_error "[email protected] failed."
        #echo -e "\033[41;37m [email protected] failed. \033[0m"
        echo ${LOG_RED} [email protected] failed.${LOG_RESET}
        exit 1
fi
}
trap 'fn_log "DO NOT SEND CTR + C WHEN EXECUTE SCRIPT !!!! "'  2