検索条件
全1件
(1/1ページ)
#!/bin/bash ###################################################################### # # Script name : template_a.sh # Usage : template_A.sh [-h] [-v] # Update : 2021.8.7 / Kazuya Jimba # yyyy.mm.dd / Name # Timing : Anytime # Timing : Cron (* * * * *) # # オリジナル配布元 http://ttm.jimba.ddo.jp/ # 改変は自由ですが、改変者の責任に基づくものとします。 ###################################################################### ### Parameter and Bariable ########################################### ## Directory pLogDir="/var/log/script" ## File pLogFile="$(basename $0 .sh).log" ## Path pLogPath="${pLogDir}/${pLogFile}" ## etc pVersion="20210807.01" ## Numbers nReportDay=0 nRV=0 ## Flag # Script log # 0 - Script log # 1 - Standard output # 2 - Standard error output # 3 - /var/log/messages fLogOutput=0 ### Function ######################################################### fnLog() { case ${fLogOutput} in 0 ) echo "$(date '+%Y/%m/%d %H:%M:%S') $*" >> ${pLogFile};; 1 ) echo "$*";; 2 ) echo "$*" >&2;; 3 ) /usr/bin/logger -t ${0##*/} "$*";; esac } fnErr() { echo "$*" >&2 fnLog "Error: $*" } fnEnd() { case ${1} in 0 ) fnLog "Normal end.";; 11 ) fnErr "Read permission not exist (${2})";; 12 ) fnErr "Write permission not exist (${2})";; 13 ) fnErr "Exec permission not exist (${2})";; 14 ) fnErr "Directory not exist (${2})";; 15 ) fnErr "File not exist (${2})";; * ) fnErr "Unknown error (${2})";; esac exit ${1} } ### Main ############################################################# # Environment check fnLog "Script start (${0##*/})" [ -d "${pLogDir}" ] || fnEnd 14 "${pLogDir}" [ -f "${pLogPath}" ] || fnEnd 15 "${pLogPath}" # Argument analyse while getopts vh tOpt; do case ${tOpt} in h ) fnLog "Option: Help message." echo "${0##*/} [-h] [-v]" echo " [-v] Version print." echo "" fnEnd 0 ;; v ) fnLog "Option: Version print." echo "Script version: ${pVersion}" echo "" fnEnd 0 ;; esac done # xxxxx ### End ############################################################## # report nReportDay=$(( $(date -u +'%d' --date="@${SECONDS}") - 1 )) fnLog "Exec Time: ${nReportDay} day $( date -u +'%H:%M:%S' --date=@${SECONDS} )" # end fnEnd ${nRV} ######################################################################
./script/ ./script/template_b.sh ./script/conf/ ./script/conf/common.cnf ./script/conf/template_b.cnf ./script/log/ ./script/tmp/展開後は、各ディレクトリ、各ファイルの権限を適切に変更してください。
#!/bin/bash ###################################################################### # # Script name : template_b.sh # Usage : template_b.sh [-h] [-v] # Update : 2021.8.8 / Kazuya Jimba # yyyy.mm.dd / Name # Timing : Anytime # Timing : Cron (* * * * *) # # オリジナル配布元 http://ttm.jimba.ddo.jp/ # 改変は自由ですが、改変者の責任に基づくものとします。 ###################################################################### ### Parameter and Bariable ########################################### # common.cnf if [ -f conf/common.cnf ];then . conf/common.cnf else echo "Not exist conf/common.cnf" exit 1 fi # template_b.cnf [ -f conf/template_b.cnf ] || fnErrEnd 11 "conf/template_b.cnf" . conf/template_b.cnf ### Main ############################################################# # Environment check fnLog "Script start (${0##*/})" [ -d "${pConfDir}" ] || fnErrEnd 14 "${pConfDir}" [ -d "${pLogDir}" ] || fnErrEnd 14 "${pLogDir}" [ -d "${pTmpDir}" ] || fnErrEnd 14 "${pTmpDir}" # Argument analyse while getopts vh tOpt; do case ${tOpt} in h ) fnLog "Option: Help message." echo "${0##*/} [-h] [-v]" echo " [-v] Version print." echo "" fnEnd ${nRV} ;; v ) fnLog "Option: Version print." echo "Script version: ${pVersion}" echo "" fnEnd ${nRV} ;; esac done # xxxxx ### End ############################################################## # report nReportDay=$(( $(date -u +'%d' --date="@${SECONDS}") - 1 )) fnLog "Exec Time: ${nReportDay} day $( date -u +'%H:%M:%S' --date=@${SECONDS} )" # end fnEnd ${nRV} ######################################################################
###################################################################### # # Script name : common.cnf # Usage : . ./common.sh # Update : 2021.8.7 / Kazuya Jimba # yyyy.mm.dd / Name # Timing : Anytime # # オリジナル配布元 http://ttm.jimba.ddo.jp/ # 改変は自由ですが、改変者の責任に基づくものとします。 ###################################################################### ### Parameter and Bariable ########################################### ## Directory pBaseDir="/usr/local/script" pConfDir="${pBaseDir}/conf" pLogDir="${pBaseDir}/log" pTmpDir="${pBaseDir}/tmp" ## File pLogFile="$(basename $0 .sh).log" ## Path pLogPath="${pLogDir}/${pLogFile}" ## etc ## Numbers nReportDay=0 nRV=0 ## Flag # Log Severity level # NAME Lv Message content # EMERG 0 System is unusable # ALERT 1 Should be corrected immediately # CRIT 2 Critical conditions # ERR 3 Error conditions # WARNING 4 May indicate that an error will occur if action is not taken. # NOTICE 5 Events that are unusual, but not error conditions. # INFO 6 Normal operational messages that require no action. # DEBUG 7 Information useful to developers for debugging the application. pLogNotifyLv=5 # Log output # 0 - Script log # 1 - Standard output # 2 - Standard error output # 3 - /var/log/messages fLogOutput=0 # ログ管理 0=通知する fEnLog=0 fEnLogEmerg=0 fEnLogAlert=0 fEnLogCrit=0 fEnLogErr=0 fEnLogWarn=0 fEnLogNotice=0 fEnLogInfo=0 fEnLogDebug=0 ### Function ######################################################### fnLog() { case ${fLogOutput} in 0 ) echo "$(date '+%Y/%m/%d %H:%M:%S') $*" >> ${pLogPath};; 1 ) echo "$*";; 2 ) echo "$*" >&2;; 3 ) /usr/bin/logger -t ${0##*/} "$*";; esac } fnEmerg() { echo "$*" >&2 [ "${fEnLogEmerg}" -eq "0" ] && fnLog "[Emergency] $*" } fnAlert() { if [ "${pLogNotifyLv}" -ge "1" ]; then echo "$*" >&2 [ "${fEnLogAlert}" -eq "0" ] && fnLog "[Alert] $*" fi } fnCrit() { if [ "${pLogNotifyLv}" -ge "2" ]; then echo "$*" >&2 [ "${fEnLogCrit}" -eq "0" ] && fnLog "[Critical] $*" fi } fnErr() { if [ "${pLogNotifyLv}" -ge "3" ]; then echo "$*" >&2 [ "${fEnLogErr}" -eq "0" ] && fnLog "[Err] $*" fi } fnWarn() { if [ "${pLogNotifyLv}" -ge "4" ]; then [ "${fEnLogWarn}" -eq "0" ] && fnLog "[Warn] $*" fi } fnNotice() { if [ "${pLogNotifyLv}" -ge "5" ]; then [ "${fEnLogNotice}" -eq "0" ] && fnLog "[Notice] $*" fi } fnInfo() { if [ "${pLogNotifyLv}" -ge "6" ]; then [ "${fEnLogInfo}" -eq "0" ] && fnLog "[Info] $*" fi } fnDebug() { if [ "${pLogNotifyLv}" -ge "7" ]; then [ "${fEnLogDebug}" -eq "0" ] && fnLog "[Debug] $*" fi } fnParam() { fnDebug '[Param] $'"$1 = $2" } fnErrEnd() { # common.cnf を利用するスクリプト共通のエラー番号 caseValue=$1 case ${caseValue} in 0) fnWarn "Normal number input...";; 1) fnErr "Read Permission error ($2)";; 2) fnErr "Write Permission error ($2)";; 3) fnErr "Exec Permission error ($2)";; 10) fnErr "Directory not exist error ($2)";; 11) fnErr "File not exist error ($2)";; *) fnErr "Unknown error (${caseValue})";; esac exit ${caseValue} } ######################################################################
###################################################################### # # Script name : template.cnf # Usage : [template.sh] . conf/template.cnf # Update : 2021.8.7 / Kazuya Jimba # yyyy.mm.dd / Name # Timing : Anytime # # オリジナル配布元 http://ttm.jimba.ddo.jp/ # 改変は自由ですが、改変者の責任に基づくものとします。 ###################################################################### ### Parameter and Bariable ########################################### ## Directory ## File ## Path ## etc pVersion="20210807.01" ## Numbers ## Flag # Log Severity level # NAME Lv Message content # EMERG 0 System is unusable # ALERT 1 Should be corrected immediately # CRIT 2 Critical conditions # ERR 3 Error conditions # WARNING 4 May indicate that an error will occur if action is not taken. # NOTICE 5 Events that are unusual, but not error conditions. # INFO 6 Normal operational messages that require no action. # DEBUG 7 Information useful to developers for debugging the application. pLogNotifyLv=5 # Log output # 0 - Script log # 1 - Standard output # 2 - Standard error output # 3 - /var/log/messages fLogOutput=0 # ログ管理 0=通知する fEnLog=0 fEnLogEmerg=0 fEnLogAlert=0 fEnLogCrit=0 fEnLogErr=0 fEnLogWarn=0 fEnLogNotice=0 fEnLogInfo=0 fEnLogDebug=0 ### Function ######################################################### fnEnd() { # template.sh で利用するエラー番号 case ${1} in 0 ) fnLog "Normal end.";; * ) fnErr "Unknown error (${2})";; esac fnLog "Script end (${0##*/})" exit ${1} } ######################################################################