Linux生产服务器Shell脚本分享

MySQL的热备份脚本

#!/bin/bash
PATH=/usr/local/sbin:/usr/bin:/bin

# The Directory of Backup
BACKDIR=/usr/mysql_backup
# The Password of MySQL
ROOTPASS=password

# Remake the Directory of Backup
rm -rf $BACKDIR
mkdir -p $BACKDIR

# Get the Name of Database
DBLIST=`ls -p /var/lib/mysql | grep / | tr -d /`
# 偷瞄了下我同事写脚本的方式,发现他直接将DBLIST一个个手动敲上去了
# 数据库少的情况是可以的,如果数据库是成百以上呢,呵呵

# Backup with Database
for dbname in $DBLIST
do
mysqlhotcopy $dbname -u root -p $ROOTPASS $BACKDIR | logger -t mysqlhotcopy
done

 

FTP同步服务器

FTPOLDDATE=`date +%Y-%m-%d -d '-60 days'`
#在FTP定义60天间的日期变量,是为了在FTP端保存60天的数据,逾期删除。

HOST=192.168.4.199
FTP_USERNAME=db
FTP_PASSWORD=password

cd ${BACKDIR}/${DATE}

ftp -i -n -v << !
open ${HOST}
user ${FTP_USERNAME} ${FTP_PASSWORD}
bin
cd ${FTPOLDDATE}
mdelete *
cd ..
rmdir ${FTPOLDDATE}
mkdir ${DATE}
cd ${DATE}
mput *
bye
!

 

 

 Keepalived的监控切换脚本

#!/bin/bash
while  :
do
nginxpid=`ps -C nginx --no-header | wc -l`
if [ $nginxpid -eq 0 ];then
/usr/local/nginx/sbin/nginx
sleep 5
  if [ $nginxpid -eq 0 ];then
  /etc/init.d/keepalived stop
  fi
fi
sleep 5 
done

 

批量生成生成帐户脚本

#!/bin/bash
for name in tom jerry joe jane
do
      useradd $name
      echo redhat | passwd --stdin $name
done

你可能感兴趣的:(linux,nginx,mysql,脚本,bash)