Cnbaby 发表于 2018-8-22 08:30:31

shell脚本集合

#!/bin/sh  
#author vperson
  
#qq 737304790
  

  
#variable
  
TOOLS=/root/toolsdown
  
NGINXDIR=/usr/local/nginx-1.4.7
  

  
#View the current user
  
[ $UID -eq0 ] ||{
  echo "Not enough authority"
  exit 1
  
}
  

  
#Create a working directory
  
mkdir -p ${TOOLS}&& cd ${TOOLS}
  
if [$? -eq 0 ]
  then
  echo "Directory created successfully"
  else
  echo "Directory creation failed"
  exit 1
  
fi
  

  
#Solve dependency package
  
yum install gcc gcc-c++ zlib-devel pcre-devel openssl-devel -y &> /dev/null || {
  
echo "Yum installation error"
  
exit 1
  
}
  

  
#Download the nginx source package
  
wget http://nginx.org/download/nginx-1.4.7.tar.gz
  
if [ $? -ne 0 ]
  then
  echo "Download nginx source package failed"
  exit 1
  else
  echo "Download nginx source package successfully"
  
fi
  

  
#Compile and install nginx
  
tar xf nginx-1.4.7.tar.gz
  
if [ $? -ne 0 ]
  then
  echo "Unpack the nginx source package failed"
  eixt 1
  else
  echo "Unpack the nginx source package successfully"
  cd nginx-1.4.7 || {
  echo "Failed to enter the nginx directory"
  exit 1
  }
  
fi
  

  
#Create a nginx user
  
useradd -r nginx
  
#if [ $? -ne 0 ]
  
#then
  
#`rpm -qa | grep nginx`&&   yum remove nginx -y
  
#fi
  

  
#Compile and install nginx
  
printf "
  
parameter\n
  
--prefix=/usr/local/nginx-1.4.7\n
  
--user=nginx\n
  
--group=nginx\n
  
--with-pcre\n
  
--with-http_ssl_module\n
  
--with-http_stub_status_module\n
  
"
  

  
./configure --prefix=/usr/local/nginx-1.4.7 \
  
--user=nginx \
  
--group=nginx \
  
--with-pcre \
  
--with-http_ssl_module \
  
--with-http_stub_status_module
  

  
if [ $? -ne 0 ]
  then
  echo "configure failed"
  exit 1
  
fi
  

  
make && make install
  
if [ $? -ne 0 ]
  then
  echo "make && make install failed"
  exit 1
  else
  echo "make && make install successfully"
  
fi
  

  
$NGINXDIR/sbin/nginx && echo "Nginx started successfully"
  
if [ $? -ne 0 ]
  then
  echo "Nginx started failed"
  
fi


页: [1]
查看完整版本: shell脚本集合