bash脚本函数添加时间戳
log_msg()
{
#time=`date +"%Y-%m-%d %H:%M:%S"`
#time=`date +%Y-%m-%d' '%H:%M:%S.%N | cut -b 1-23` #打印毫秒
time=`date +"%F %T"`
echo "$time [LOG] $1$2"
}
err_msg()
{
#time=`date +"%Y-%m-%d %H:%M:%S"`
#time=`date +%Y-%m-%d' '%H:%M:%S.%N | cut -b 1-23` #打印毫秒
time=`date +"%F %T"`
echo -e "\033[5;41;33m $time [ERROR] $1$2 \033[0m"
}
a="qqq"
log_msg "$a step1 success" >1.txt
sleep 1
log_msg "step2 success"
sleep 2
log_msg "step3 success"
exit 0