检测redis存活状态,若检测到挂掉,那么立马启动redis
#! /bin/bash
## 检测redis如果挂了就立马启动
a=`ps aux|grep redis |awk '{print $1}'|grep redis`
if [ -z $a ];then
/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
fi
创建一个函数,可以接受一个磁盘设备路径(如/dev/sdb)作为参数;在真正开始后面步骤之前提醒用户有危险,并让用户选择是否继续;而后将此磁盘设备上的所有分区清空(提示,使用命令dd if=/dev/zeroof=/dev/sdb bs=512 count=1实现,注意其中的设备路径不要写错了 ;如果此步骤失败,返回67给主程序;接着在此磁盘设备上创建两个主分区,一个大小为100M,一个大小为1G;如果此步骤失败,返回68给主程序; 格式化此两分区,文件系统类型为ext3;如果此步骤失败,返回69给主程序;如果上述过程都正常,返回0给主程序;
2、调用此函数;并通过接收函数执行的返回值来判断其执行情况,并将信息显示出来;
#! /bin/bash
function disk() {
read -p "Input the device you want to format. " dev
read -p "Waring! It will be format the device $dev, and the data on$dev will be deleted, are you sure to do this? Y/N " k
while :; do
if [ $k == 'N' -o $k == 'n' ]; then
exit
elif [ $k == 'Y' -o $k == 'y' ]; then
dd if=/dev/zero of=$dev bs=512 count=1
n1=`echo $?`
if [ $n1 -ne 0 ]; then
return 67
else
echo -e "n\np\n1\n1\n+100M\nn\np\n2\n\n+1G\nw\nquit\n"|fdisk $dev
fi
n2=`echo $?`
if [ $n2 -ne 0 ]; then
return 68
else
mkfs.ext3 /dev/sdb1 && mkfs.ext3 /dev/sdb2
fi
n3=`echo $?`
if [ $n3 == 0 ]; then
return 0
else
return 69
fi
else
continue
fi
done
}
disk
n4=`echo $?`
if [ $n4 == 67 ]; then
echo "Delete the partition table error."
elif [ $n4 == 68 ]; then
echo "Reinstall the partition table error."
elif [ $n4 == 69 ]; then
echo "Format the patition error."
else
echo "The whole opration is successful!"
fi
本文转自super李导51CTO博客,原文链接:http://blog.51cto.com/superleedo/1892450 ,如需转载请自行联系原作者