`
sillycat
  • 浏览: 2487446 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Jenkins Configuration(4)Improve Shell Script Debug/Info Message

 
阅读更多
Jenkins Configuration(4)Improve Shell Script Debug/Info Message
Just take example from my colleagues' scripts. I found I can improve my shell script to give some debug or info messages.

Just take this test.sh as example:

#!/bin/sh

#Parameters

#define the log file directory
LOGFILE=/var/log/test.log
#debug flag
DEBUG=0
#info flag
INFO=1

#Functions

debug() {
if [ "$DEBUG" -gt 0 ] ; then
  NOW=$(date +"%m-%d-%Y %H:%M:%S")
  echo "DEBUG [$NOW] $1" | tee -a $LOGFILE
fi
}

info() {
if [ "$INFO" -gt 0 ] ; then
  NOW=$(date +"%m-%d-%Y %H:%M:%S")
  echo "INFO [$NOW] $1" | tee -a $LOGFILE
fi
}

info "Some information will echo here"

debug "Some debug information will echo here"


References:


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics