1、keepalived检测nginx脚本
#!/bin/bash
# author:gan_ke
# this scripts is used for keepalived to check nginx status
A=`ps -C nginx --no-header |wc -l` #查看当前是否有nginx 进程
if [ $A -eq 0 ];then
/usr/local/nginx/sbin/nginx #重启nginx
if [ `ps -C nginx --no-header |wc -l` -eq 0 ];then #nginx重启失败,则停掉keepalived服务,进行VIP转移
killall keepalived #强制kill关于keepalived的进程(实现高可用)
fi
fi
2、每天定时备份http的访问日志
#!/bin/sh
# author:gan_ke
# this scripts backup http access_log everyday
cd /var/log/httpd/
##备份日志
/bin/mv access_log access_$(date +%F).log
##重载服务(平滑,不影响业务)
/etc/init.d/httpd reload
这是脚本,完成后还要加入定时任务:
30 5 * * * /bin/sh /scripts/cut_http_log.sh
3、检查系统是否装某个软件,没有则安装
#!/bin/bash
# author: gan_ke
# this script is check the service on your system,if no,then install it
# 使用命令查看是否有包安装上
res=`rpm -qa $1 | wc -l`
if [ $res -eq 0 ] ; then
yum install -y $1
else
echo "$1 is already installed."
fi
4、在指定目录下,通过5个随机字母+ganke创建10个txt文件
#!/bin/bash
# author:gan_ke
# this script is touch file with random name
#先判断目录是否存在,若不存在则创建目录
[ -d /root/test ] || mkdir /root/test -p
cd /root/test
for i in `seq 10`
do
touch `echo $RANDOM|md5sum|cut -c 1-5|tr "[0-9]" "[a-z]"`_ganke.txt
done