#!/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] $@" >> ${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] $@ \033[0m" >> ${LOG_FILE} #执行失败日志打印路径
}
function fn_log () {
if [ $? -eq 0 ];then
log_info "$@ sucessed."
#echo -e "\033[32m $@ sucessed. \033[0m"
echo ${LOG_GREEN} $@ sucessed.${LOG_RESET}
else
log_error "$@ failed."
#echo -e "\033[41;37m $@ failed. \033[0m"
echo ${LOG_RED} $@ failed.${LOG_RESET}
exit 1
fi
}
trap 'fn_log "DO NOT SEND CTR + C WHEN EXECUTE SCRIPT !!!! "' 2