shell脚本示例
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了shell脚本示例相关的知识,希望对你有一定的参考价值。
#!/bin/bash
#######################################################
# Name: shell_exp.sh
# Version: v21.0
# Function: Backup mysql Databases Template Script
# Author: zz
# Create Date: 2016-12-03
# Description: study
#######################################################
# Shell Env
SHELL_NAME="shell_template.sh"
SHELL_DIR="/tmp/shell"
SHELL_LOG="${SHELL_DIR}/${SHELL_NAME}.log"
LOCK_FILE="/tmp/${SHELL_NAME}.lock"
#Write Log
shell_log(){
LOG_INFO=$1
echo "$(date "+%Y-%m-%d") $(date "+%H-%M-%S") : ${SHELL_NAME} : ${LOG_INFO}" >> ${SHELL_LOG}
}
# Shell Usage
shell_usage(){
echo $"Usage: $0 {backup}"
}
shell_lock(){
touch ${LOCK_FILE}
}
shell_unlock(){
rm -f ${LOCK_FILE}
}
# Backup MySQL All Database with mysqldump or innobackupex
mysql_backup(){
if [ -f "$LOCK_FILE" ];then
shell_log "${SHELL_NAME} is running"
echo "${SHELL_NAME}" is running && exit
fi
shell_log "mysql backup start"
shell_lock
sleep 15
shell_log "mysql backup stop"
shell_unlock
}
# Main Function
main(){
case $1 in
backup)
mysql_backup
;;
*)
shell_usage;
esac
}
#Exec
main $1
本文出自 “银河系|计算机网络” 博客,请务必保留此出处http://qqran.blog.51cto.com/10014850/1879203
以上是关于shell脚本示例的主要内容,如果未能解决你的问题,请参考以下文章