首页 > 代码库 > shell脚本示例
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脚本示例
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。