SHELL 脚本小技巧
生活随笔
收集整理的這篇文章主要介紹了
SHELL 脚本小技巧
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
腳本很簡單,直接上功能介紹及腳本,可以做模板使用:
#!/bin/bash ####################################################### # $Version: v1.0 # $Function: Shell Template Script # $Author: Jerry.huang # $organization: http://www.cnblogs.com/Mrhuangrui # $Create Date: 2017-06-30 09:30 # $Description: You know what i mean,heiheihei ######################################################## Shell Env SHELL_DIR="/opt/shell" SHELL_LOG="${SHELL_DIR}/$0.log" LOCK_FILE="/tmp/$0.lock"#Write Log shell_log(){LOG_INFO=$1echo "$(date "+%Y-%m-%d") $(date "+%H-%M-%S") : $0 : ${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" ];thenshell_log "$0 is running"echo "$0" is running,exit now. && exitfishell_log "mysql backup start"shell_locksleep 10shell_log "mysql backup stop"shell_unlock }# Main Function main(){case $1 inbackup)mysql_backup;;*)shell_usage;esac }#Exec main $1 shell_template.sh
?
轉載于:https://www.cnblogs.com/Mrhuangrui/p/7097453.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的SHELL 脚本小技巧的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java线程与Linux内核线程的映射关
- 下一篇: VB 2010 (32)泛型方法