標籤:efi dev conf his proc sleep lsof define grep
當然這個部落格原代碼是轉載大神的。。。
自動安裝Nginx指令碼,採用case方式,選擇方式,也可以根據實際需求改成自己想要的指令碼mynginx.sh
- #!/bin/sh
-
- ###nginx install shell
- ###wugk 2012-07-14
- ###PATH DEFINE
-
- SOFT_PATH=/data/soft/
- NGINX_FILE=nginx-1.2.0.tar.gz
- DOWN_PATH=http://nginx.org/download/
-
- if[ $UID -ne 0 ];then
- echo This script must use administrator or root user ,please exit!
- sleep 2
- exit 0
- fi
-
- if[ ! -d $SOFT_PATH ];then
- mkdir -p $SOFT_PATH
- fi
-
- download ()
- {
- cd $SOFT_PATH ;wget $DOWN_PATH/$NGINX_FILE
- }
-
- install ()
- {
- yum install pcre-devel -y
- cd $SOFT_PATH ;tar xzf $NGINX_FILE ;cd nginx-1.2.0/ &&./configure –prefix=/usr/local/nginx/ –with-http_stub_status_module –with-http_ssl_module
- [ $? -eq 0 ]&&make &&make install #[ ]條件判斷用的可以
- }
-
- start ()
- {
- lsof -i :80[ $? -ne 0 ]&&/usr/local/nginx/sbin/nginx #lsof -i :80 //顯示所有開啟80連接埠的進程
- }
-
- stop ()
- {
- ps -ef |grep nginx |grep -v grep |awk ‘{print $2}’|xargs kill -9 #本文最nice的一個就是用了xargs這個命令,將上一個命令的輸出作為下一個命令的參數
- }
-
- exit ()
- {
- echo $? ;exit
- }
-
- ###case menu #####
-
- case $1 in
- download )
- download
- ;;
-
- install )
- install
- ;;
-
- start )
- start
- ;;
- stop )
- stop
- ;;
-
- * )
-
- echo “USAGE:$0 {download or install or start or stop}”
- exit
- esac
指令碼執行:
./mynginx.sh download
./mynginx.sh install
./mynginx.sh start
./mynginx.sh stop
linux shell每天一閱 -- 安裝nginx