shell脚本安装nginx,使用case判断

#!/bin/bash
yum -y install gcc pcre-devel zlib-devel &> /dev/null 
mkdir nginx
cd /root/nginx
tar -zxf nginx-1.12.2.tar.gz
cd nginx-1.12.2
./configure --prefix=/usr/local/nginx &> /dev/null
make &> /dev/null
make install &> /dev/null
echo "nginx安装成功"
sh="/usr/local/nginx/sbin/nginx"
ki="/usr/local/nginx/logs/nginx.pid
case $1 in
        start)
        echo "正在启动nginx......"
        $sh
        echo "启动成功"
        ;;
        stop)
        echo "正在停止nginx....."
        kill -s QUIT $(cat $ki) &> /dev/null
        echo "已停止"
        ;;
        restart)
        $0 stop
        $0 start
        ;;
        *)
        echo "使用命令: $0 {start|stop|restart}"
esac

你可能感兴趣的:(shell脚本)