歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> SHELL編程 >> shell格式化日志輸出

shell格式化日志輸出

日期:2017/3/1 13:52:55   编辑:SHELL編程
shell格式化日志輸出 #!/bin/ksh init_variables() { if [ -s $HOME/.profile ] then . $HOME/.profile fi if [ -s $HOME/.bash_profile ] then . $HOME/.bash_profile fi if [ `uname | tr '[A-Z]' '[a-z]'` = "linux" ] then echo_cmd='echo -e' unalias ls 2>/dev/null 1>&2 awk_cmd='awk --posix' else echo_cmd='echo' awk_cmd='awk' fi log_file=${dir_name}/${script_name}.log log_cmd_info="eval $echo_cmd \"[$dir_name/$script_name]\" @\`date +\"%Y%m%d %T\"\` [info]:" log_cmd_error="eval $echo_cmd \"[$dir_name/$script_name]\" @\`date +\"%Y%m%d %T\"\` [error]:" } main_fun() { ${log_cmd_info} "this is info message." | tee -a ${log_file} ${log_cmd_error} "this is error message." | tee -a ${log_file} } ######################################## # main entrence ######################################## #1.get filename script_name=`basename $0` dir_name=`dirname $0` #2.run init_variables init_variables; #3.run main_fun main_fun; #4.exit exit 0 ######################################## # end of script ########################################
Copyright © Linux教程網 All Rights Reserved