博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux Shell脚本欣赏
阅读量:5255 次
发布时间:2019-06-14

本文共 3825 字,大约阅读时间需要 12 分钟。

 MySQL Backup Shell Script

#!/bin/bash# A sample mysql backup script# Must be run as the root user# Written by Vivek Gite# Last updated on : 23/Aug/2003# ---------------------------------# MySQL Login InfoMUSER="admin"             # MySQL userMHOST="192.168.1.100"        # MySQL server ipMPASS="MySQLServerPassword"     # MySQL password# format dd-mm-yyyy NOW=$(date +"%d-%m-%Y")# Backupfile pathBPATH=/backup/mysql/$NOW# if backup path does not exists, create it [ ! -d $BPATH ] && mkdir -p $BPATH# get database name listsDBS="$(/usr/bin/mysql -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"for db in $DBSdo    # Bakcup file name    FILE="${BPATH}/${db}.gz"        # skip database backup if database name is adserverstats or mint    [ "$db" == "adserverstats"  ] && continue    [ "$db" == "mint"  ] && continue        # okay lets dump a database backup     /usr/bin/mysqldump -u $MUSER -h $MHOST -p$MPASS $db | /bin/gzip -9 > $FILEdone

 

Start PHP Service in jail

#!/bin/sh# A shell script to start / stop php-cgi process.# Author: Vivek Gite 
# Last updated on June-23-2007.# ----------------------------------------------fFCGI=/usr/bin/spawn-fcgifIP=127.0.0.1fPORT=9000fUSER=phpjailfGROUP=phpjailfCHILD=10fJAILDIR=/phpjailfPID=/var/run/fcgi.php.pidfPHPCGI=/usr/bin/php-cgi# path to binary files.PKILL=/usr/bin/pkillRM=/bin/rmPGREP=/usr/bin/pgrepGREP=/bin/grepID=/usr/bin/id# Must be run as root else die[ $(${ID} -u) -eq 0 ] || { echo "$0: Only root may run this script."; exit 1; }# Jail user must exits else die${GREP} -q $fUSER /etc/passwd || { echo "$0: User $fUSER not found in /etc/passwd."; exit 2; }# Jail group must exits else die${GREP} -q $fGROUP /etc/passwd || { echo "$0: Group $fGROUP not found in /etc/group."; exit 3; }# Jail directory must exits else die[ ! -d ${fJAILDIR} ] && { echo "$0: php-cgi jail directory \"${fJAILDIR}\" not found."; exit 4; }# Use case to make decision case "$1" in start) # start php-cgi in jail at given IP and server port $fFCGI -a $fIP -p $fPORT -u $fUSER -g $fGROUP -C $fCHILD -c $fJAILDIR -P $fPID -- $fPHPCGI [ $? -eq 0 ] && echo "Starting php-cgi .. [ OK ]" || echo "Starting php-cgi .. [ FAILED ]" ;; stop) # make sure php-cgi is running read line < "$fPID" if [ -d /proc/$line ] then # kill php-cgi owned by user ${PKILL} -KILL -u $fUSER php-cgi [ $? -eq 0 ] && echo "Stopping php-cgi .. [ OK ]" \ || echo "Stopping php-cgi .. [ FAILED ]" ${RM} -f $fPID else echo "$0: php-cgi is not running." fi ;; status) # find out if php-cgi is running or not ${PGREP} -u ${fUSER} php-cgi >/dev/null 2>&1 [ $? -eq 0 ] && echo "$0: php-cgi is running at $fIP:$fPORT" \ || echo "$0: php-cgi is not running at $fIP:$fPORT" ;; *) # display usage echo "Usage: $0 {start|stop|status}"esac

 

Create a shell script called progressdots.sh

#!/bin/bash# progressdots.sh - Display progress while making backup# Based on idea presnted by nixCraft forum user rockdalinux# Show progress dotsprogress(){  echo -n "$0: Please wait..."  while true  do    echo -n "."    sleep 5  done}dobackup(){    # put backup commands here    tar -zcvf /dev/st0 /home >/dev/null 2>&1}# Start it in the backgroundprogress &# Save progress() PID# You need to use the PID to kill the functionMYSELF=$!# Start backup# Transfer control to dobackup()dobackup# Kill progresskill $MYSELF >/dev/null 2>&1echo -n "...done."echo

 

转载于:https://www.cnblogs.com/bluejavababy/p/5048342.html

你可能感兴趣的文章
Java大数——a^b + b^a
查看>>
poj 3164 最小树形图(朱刘算法)
查看>>
服务器内存泄露 , 重启后恢复问题解决方案
查看>>
android一些细节问题
查看>>
KDESVN中commit时出现containing working copy admin area is missing错误提示
查看>>
利用AOP写2PC框架(二)
查看>>
【动态规划】skiing
查看>>
java定时器的使用(Timer)
查看>>
ef codefirst VS里修改数据表结构后更新到数据库
查看>>
boost 同步定时器
查看>>
[ROS] Chinese MOOC || Chapter-4.4 Action
查看>>
简单的数据库操作
查看>>
iOS-解决iOS8及以上设置applicationIconBadgeNumber报错的问题
查看>>
亡灵序曲-The Dawn
查看>>
Redmine
查看>>
帧的最小长度 CSMA/CD
查看>>
xib文件加载后设置frame无效问题
查看>>
编程算法 - 左旋转字符串 代码(C)
查看>>
IOS解析XML
查看>>
Python3多线程爬取meizitu的图片
查看>>