shell 脚本汇总 (持续更新中)

文章目录

    • 1、计算从1到100所有整数的和
    • 2、提示用户输入一个小于100的整数,并计算从1到该数之间所有整数的和
    • 3、求从1到100所有整数的偶数和、奇数和
    • 4、写个逛淘宝选购商品脚本,每家商店有五种商品选购(衣服500元,裤子400元,鞋子350元,帽子150元,袜子50元),每次选购完或不买都会提示用户是否继续逛下一家商店,如果不再继续逛的话进行购物车结算总额。
    • 5、shell 计算器
    • 6、99乘法表
    • 7、正等腰三角形与倒等腰三角形
    • 8、直角三角形
    • 9、批量添加用户
    • 10、根据IP地址,批量检查主机状态
    • 11、猜商品价格
    • 12、直线
    • 13、矩形
    • 14、平行四边形
    • 15、梯形
    • 16、菱形
    • 17、输出环境变量PATH所包含的所有目录以及其中的所有可执行文件
    • 18、执行脚本输入用户名,若该用户存在,输出提示该用户已存在;若该用户不存在,提示用户输入密码,建立用户并设立其密码
    • 19、检测指定范围主机是否通信,并将通信的主机ip输出到文件host_ip中
    • 20、mkdir -p /root/bin/aa/bb/cc/dd ; touch /root/bin/aa/bb/cc/dd/abc.txt,输出环境变量PATH所包含的所有目录以及其中的子目录和所有不可执行文件
    • 21、菱形通过传参控制形状的可大可小
    • 22、使用shell 一键部署DNS正向解析
    • 23、使用免交互,一键进行PXE批量装机shell脚本
    • 24、一键部署Apache服务
    • 25、一键部署MySQL脚本
    • 26、使用脚本切割Nginx日志并收集
    • 27、一键安装Nginx服务
    • 28、一键部署LNMP
    • 29、一键部署LAMP
    • 30、监控Linux缓存并清理脚本

1、计算从1到100所有整数的和

[root@gcc?~]#vim test1.sh
#!/bin/bash              
#this is zhengshuhe    
sum=0                  
for i in {1..100}        
do                       
  sum=$[$i+$sum]         
done                    
echo $sum               

[root@gcc ~]#chmod +x test1.sh      
[root@gcc ~]#./test1.sh             
5050                                
[root@gcc?~]#vim test7.sh
#!/bin/bash
a=1
sum=0
while [ $a -le 100 ]         
do
  sum=$[$sum+$a]
  let a++                    
done
echo $sum

[root@gcc ~]#sh test7.sh 
5050

2、提示用户输入一个小于100的整数,并计算从1到该数之间所有整数的和

方法一:

[root@gcc ~]#vim demo3.sh 
#!/bin/bash
read -p "请输入1-100之间的一个整数:" a
sum=0
for ((i=1;i<=a;i++))
do
   sum=$[$sum+$i]
done
echo "从1到$i的整数和为:$sum"

[root@gcc ~]#sh demo3.sh 
请输入1-100之间的一个整数:3
从1到4的整数和为:6

方法二:

[root@gcc ~]#vim demo3.sh 
#!/bin/bash
sum=0
read -p "请输入1-100之间的一个整数:" a
while [ $a -ge 1 ]
do
  sum=$[$sum+$a]
  let a--
done
echo "从1到$a的整数和为

[root@gcc ~]#sh demo3.sh 
请输入1-100之间的一个整数:3
从1到0的整数和为:6

3、求从1到100所有整数的偶数和、奇数和

方法一:

[root@gcc ~]#vim demo4.sh
#!/bin/bash
a=0
b=0
for i in {0..100..2}
do
   a=$[$a+$i]
done
echo "所有整数和为:$a"
for i in {1..100..2}
do
  b=$[$b+$i]
done
echo "所有奇数和为:$b"

[root@gcc ~]#sh demo4.sh 
所有整数和为:2550
所有奇数和为:2500

方法二:

[root@gcc ~]#vim demo4.sh

#!/bin/bash
jishuhe=0
oushuhe=0
i=1
p=0
while [ $i -le 100 ] 
do
   jishuhe=$[$jishuhe+$i]
   let i=$[$i+2]
done
echo "所有奇数和为:$jishuhe"

while [ $p -le 100 ]
do
  oushuhe=$[$oushuhe+$p]
  let p=$[$p+2]
done
echo "所有偶数和为:$oushuhe"

[root@gcc ~]#sh demo4.sh 
所有奇数和为:2500
所有偶数和为:2550

4、写个逛淘宝选购商品脚本,每家商店有五种商品选购(衣服500元,裤子400元,鞋子350元,帽子150元,袜子50元),每次选购完或不买都会提示用户是否继续逛下一家商店,如果不再继续逛的话进行购物车结算总额。

#!/bin/bash
#shang ping xuan gou
echo "================================="
echo "------WELCOME-GCC-MARKET---------"
echo "=================================" 
read -p "您是否进入商店进行购物?(yes/no)" INT
   while [ $INT = "yes" ]
     do
       echo "1.衣服500元"
       echo "2.裤子400元"
       echo "3.鞋子350元"
       echo "4.帽子150元"
       echo "5.袜子50元"

       read -p "请问你要购买哪种商品?(请输入序号)" node
       read -p "是否继续购买?(yes/no)" INT
     case $node in
     1)
     let cost+=500
     echo "消费"$cost"元" 
     ;;
     2)
     let cost+=400
     echo "消费"$cost"元"
     ;;
     3)
     let cost+=350
     echo "消费"$cost"元" 
     ;;
     4)
     let cost+=150
     echo "消费"$cost"元" 
     ;;
     5)
     let cost+=50
     echo "消费"$cost"元"
     ;;
     *)
      echo "输入错误,请重输!"
     esac
     if [ $INT = "no" ]
     then
     break
     fi
 done
echo "您本次逛街总共花费"$cost"元" 

5、shell 计算器

#!/bin/bash
read -p "请输入第一个整数:" num1
read -p "请输入运算符:加(+);减(-);乘(x);除(/);趋于(%):" fh
read -p "请输入第二个整数:" num2
if [ $fh = "+" ]
 then
     echo "结果为:`expr $num1 + $num2`"
elif [ $fh = "-" ]
  then
     echo "结果为:`expr $num1 - $num2`"
elif [ $fh = "x" ]
  then
      echo "结果为:`expr $num1 \* $num2`"
elif [ $fh = "/" ]
  then
      echo "结果为:`expr $num1 / $num2`"
elif [ $fh = "%" ]
   then
      echo "结果为:`expr $num1 % $num2`"
else
   echo "输入有误!"
fi

6、99乘法表

方法一:

for ((a=1;a<=9;a++))
do
        for ((b=1;b<=9;b++))
        do
        if [[ a -ge b ]];then
                echo -n "$b*$a=$[a*b] "
        fi
        done
        echo " "
done

方法二:

#!/bin/bash
for ((i=1;i<=9;i++))
do
        for ((j=1;j<=i;j++))
        do
                echo -n "$j*$i=$[$i*$j] "
                if [ $i -eq $j ]
                then
                        echo -e '\n'
                fi
        done
done

方法三:

[root@gcc opt]#vim e.sh

#!/bin/bash
for ((a=1;a<=9;a++))
do
   for ((b=1;b<=$a;b++))
   do
     c=$[ $a*$b ]
     echo -ne "$a*$b=$c\t"
   done
   echo ""
done

7、正等腰三角形与倒等腰三角形

正等腰三角形

方法一:

read -p "请输入长度: " n
for i in `seq 1 $n`
do
   for ((j=$n;j>i;j--))
   do
      echo -n " "
   done

   for m in `seq 1 $i`
   do
     echo -n " * "
   done
   echo 
done

方法二:

[root@gcc opt]#vim k.sh
#!/bin/bash
for ((a=1;a<=9;a++))
do
  for ((b=9;b>=$a;b--))
  do
    echo -n " "
  done
  for ((c=1;c<=$a;c++))
  do
    echo -n "*"
  done
  for ((d=2;d<=$a;d++))
  do
    echo -n "*"
  done
  echo ""
done

[root@gcc opt]#sh k.sh 
         *
        ***
       *****
      *******
     *********
    ***********
   *************
  ***************
 *****************

方法三:

[root@gcc opt]#vim k.sh
#!/bin/bash
for ((a=1;a<=9;a++))
do
  for ((b=9;b>=$a;b--))
  do
    echo -n " "
  done
  i=$[($a*2)-1]
  for ((h=1;h<=$i;h++))
  do
    echo -n "*"
  done
  echo ""
  done

[root@gcc opt]#sh k.sh 
         *
        ***
       *****
      *******
     *********
    ***********
   *************
  ***************
 *****************

倒等腰三角形

[root@gcc opt]#vim m.sh 
#!/bin/bash
for ((a=1;a<=9;a++))
do
  for ((b=1;b<=$a;b++))
  do
  echo -n " "
  done
    for ((c=9;c>=$a;c--))
    do
    echo -n "*"
    done
    for ((d=8;d>=$a;d--))
    do
    echo -n "*"
    done
    echo ""
done

[root@gcc opt]#sh m.sh 
 *****************
  ***************
   *************
    ***********
     *********
      *******
       *****
        ***
         *

8、直角三角形

方法一:

!/bin/bash
#直角三角形
read -p "请输入长度:" n
for i in `seq 1 $n`
do
   for ((j=1;j<=$i;j++))
    do
      echo -n "*"
    done
echo
done

方法二:(输出正三角)

[root@gcc opt]#vim g.sh
#!/bin/bash
for ((a=1;a<=9;a++))
do
  for ((b=1;b<=$a;b++))
  do
    echo -n "*"
  done
  echo ""
done

[root@gcc opt]#sh i.sh 
*
**
***
****
*****
******
*******
********
*********

方法三:(输出倒三角)

[root@gcc opt]#vim j.sh
#!/bin/bash
for ((a=1;a<=9;a++))
do
  for ((b=9;b>=$a;b--))
  do
    echo -n "*"
  done
  echo ""
done

[root@gcc opt]#sh j.sh 
*********
********
*******
******
*****
****
***
**
*

方法四:(靠右三角形)

[root@gcc opt]#vim k.sh
#!/bin/bash
for ((a=1;a<=9;a++))
do
  for ((b=9;b>=$a;b--))
  do
    echo -n " "
  done
  for ((c=1;c<=$a;c++))
  do
    echo -n "*"
  done
  echo ""
done

[root@gcc opt]#sh k.sh 
         *
        **
       ***
      ****
     *****
    ******
   *******
  ********
 *********

9、批量添加用户

[root@gcc ~]#touch user.txt     #首先创建一个包含所有需要创建账号的用户名
[root@gcc ~]#vim user.txt 
wangyi             #注意一个姓名之间不要有空格
wanger
wangsan
wangsi

[root@gcc ~]#vim test2.sh      #编辑脚本
#!/bin/bash
#pi liang tianjia yonghu
a=$(cat /root/user.txt)        #定义变量a,使a遍历user.txt,注意遍历的文件要使用绝对路径
for i in $a                    #定义变量i,使i使用$a中的内容
do
   useradd $i                  #添加用户,用户名从变量i中获取
   echo "123123" | passwd --stdin $i     #给用户添加密码,密码从$i中获取
   echo "$i添加成功!"
done

(优化脚本:echo "123123" | passwd --stdin $i &> /dev/null)

或者

[root@gcc ~]#vim test5.sh
#!/bin/bash
i=1                      #用户从1开始
while [ $i -le 20 ]      #当小于等于20时一直执行while循环,直到20停止循环
do    
  useradd stu$i
  echo "123123" | passwd --stdin stu$i &> /dev/null
  echo "stu$i添加成功!"
  let i+=1            #用户每次+1进行添加
done

10、根据IP地址,批量检查主机状态

[root@gcc ~]#touch ipadds.txt
[root@gcc ~]#vim ipadds.txt 
[root@gcc ~]#vim ipadds.txt      #在文本中添加需要检查的主机的IP地址
192.168.200.1
192.168.200.2
192.168.200.3
192.168.200.4
192.168.200.5

[root@gcc ~]#vim test3.sh       #编写脚本
#!/bin/bash
a=`cat /root/ipadds.txt`        #遍历ipadds.txt文件
for i in $a                     #定义变量i从$a中取值
do
   ping -c 3 -i 0.2 -W 3 $i &> /dev/null     #开始ping检测,-c是ping的次数,-i是每次ping的时间,-w是ping的时候延时时间
   if [ $? -eq 0 ]              #判断语句,当使用$?返回0时,说明上面ping成功
   then
   echo "$i开启!"
   else
   echo "$i关闭!"
   fi
done

11、猜商品价格

[root@gcc ~]#vim test6.sh
#!/bin/bash
a=$[$RANDOM  % 1000]         
c=0                          
while [ $b -lt 1 ]     
do
let c++                      
read -p "请输入商品价格:" i
if [ $i -lt $a  ]
then
   echo "猜小了,再来一次。"
elif [ $i -gt $a ]
then
   echo "猜大了,再来一次。"
elif [ $i -eq $a ]
then
   echo "恭喜,猜对了!"
   b=2                      
fi
done
echo "你一共猜了$c次"        

12、直线

[root@gcc opt]#vim f.sh
#!/bin/bash
for ((a=1;a<=20;a++))
do
  echo -n "*"
done
echo ""

13、矩形

[root@gcc opt]#vim g.sh
#!/bin/bash
for ((i=1;i<=5;i++))
do
  for ((a=1;a<=10;a++))
  do
    echo -n "*"
  done
  echo ""
done

14、平行四边形

方法一:

[root@gcc opt]#vim d.sh
#!/bin/bash
for ((a=1;a<=9;a++))
do
  for ((b=9;b>=$a;b--))
  do
   echo -n " "
  done
     for ((c=1;c<=9;c++))
     do
     echo -n "*" 
     done
     echo ""
done

方法二:

#!/bin/bash
for ((i=1;i<=9;i++))
do
  for ((j=9;j>=i;j--))
  do
    echo -n " "
  done
      for ((j=2;j<=i;j++))
      do
        echo -n "*"
      done
          for ((j=1;j<=i;j++))
          do
          echo -n "*"
          done
             for ((j=9;j>=i;j--))
             do
             echo -n "*"
             done
                for ((j=9;j>=i;j--))
                do
                echo -n "*"
                done
                echo 
done

15、梯形

直角梯形:

[root@gcc opt]#vim l.sh
#!/bin/bash
for ((a=1;a<=9;a++))
do
  for ((b=9;b>=$a;b--))
  do
   echo -n " "
  done
     for ((c=1;c<=9+$a;c++))
     do
     echo -n "*" 
     done
     echo ""

[root@gcc opt]#sh l.sh 
         **********
        ***********
       ************
      *************
     **************
    ***************
   ****************
  *****************
 ******************

等腰三梯形:

[root@gcc opt]#vim l.sh

#!/bin/bash
for ((a=1;a<=9;a++))
do
  for ((b=9;b>=$a;b--))
  do
   echo -n " "
  done
     for ((c=1;c<=9+$a;c++))
     do
     echo -n "*" 
     done
     for ((d=1;d<=$a;d++))
     do
       echo -n "*"
     done
     echo ""
done

[root@gcc opt]#sh l.sh 
         ***********
        *************
       ***************
      *****************
     *******************
    *********************
   ***********************
  *************************
 ***************************

16、菱形

方法一:

#!/bin/bash
read -p "please input the longs:" long
for((i=1;i<=$long;i++))       #控制行数 
do
    for((j=$long;j>i;j--))    #控制空格输出 
    do
        echo -n " " 
    done

    let "g=2*i-1"

    for m in `seq 1 $g`       #控制*数量 
    do
        echo -n "*" 
    done

    echo "" 
done

for((i=2;i<=$long;i++))       #控制行数 
do
    for ((j=1;j

方法二:

#!/bin/bash
for((i=9;i>=1;i--))
do
  for((a=1;a<=$i;a++))
do
  echo -n " "
  done
  for((b=9;b>=$i;b--))
do
  echo -n "*"
  done
  for((c=8;c>=$i;c--))
do
  echo -n "*"
  done
echo ""
done

for((i=2;i<=9;i++))
do
  for((a=1;a<=$i;a++))
do
  echo -n " "
  done
  for((b=9;b>=$i;b--))
do
  echo -n "*"
  done
  for((c=8;c>=$i;c--))
do
  echo -n "*"
  done
echo ""
done

17、输出环境变量PATH所包含的所有目录以及其中的所有可执行文件

[root@gcc ~]#vim demo7.sh

#!/bin/bash
IFS_OLD=$IFS
IFS=$IFS':'
for folder in $PATH
do
  echo "$folder:"
  for file in $(ls $folder)
  do
    if [ -f $folder/$file -a -x $folder/$file ]
    then
        echo " $folder/$file"
    fi
  done
done

IFS=${IFS_OLD}

18、执行脚本输入用户名,若该用户存在,输出提示该用户已存在;若该用户不存在,提示用户输入密码,建立用户并设立其密码

#!/bin/bash
abc () {
   read -p "请输入用户名:" user
   id $user &> /dev/null
   if [ $? -eq 0 ]
    then 
	   echo ""$user"用户已存在!"
    elif [ $? -ne 0 ]
    then 
	   read -p "创建新用户"$user",请输入用户密码:" pass
	   useradd $user
	   echo "$pass" | passwd --stdin $user
   fi   
} 

abc

19、检测指定范围主机是否通信,并将通信的主机ip输出到文件host_ip中

#!/bin/bash
abc () {
for i in {1..10}
do
ping -c 1 -i 0.2 -w 1 192.168.200.$i &> /dev/null
   if [ $? -eq 0 ]
   then 
       echo ""192.168.200.$i"已经开启" >> /opt/host_ip
   else
       echo ""192.168.200.$i"未开启"
   fi
done
}

abc 

20、mkdir -p /root/bin/aa/bb/cc/dd ; touch /root/bin/aa/bb/cc/dd/abc.txt,输出环境变量PATH所包含的所有目录以及其中的子目录和所有不可执行文件

#!/bin/bash
function list_files {
    for f in `ls $1`
    do
      if [ -d "$1/$f" ]
      then
          echo "$2$f"
          list_files "$1/$f" "$2"
      elif [ ! -x "$1/$f" ]
	  then 
          echo "$2$f"
      fi
     done
}


IFS_OLD=$IFS
IFS=$IFS":"
for i in $PATH
do
  echo "$i"
  list_files "$i" " "
done
IFS=$IFS_OLD

21、菱形通过传参控制形状的可大可小

#!/bin/bash
abc () {
for((i=$1;i>=1;i--))
do
  for((a=1;a<=$i;a++))
do
  echo -n " "
  done
  for((b=$1;b>=$i;b--))
do
  echo -n "*"
  done
  for((c=$1-1;c>=$i;c--))
do
  echo -n "*"
  done
echo ""
done

for((i=2;i<=$1;i++))
do
  for((a=1;a<=$i;a++))
do
  echo -n " "
  done
  for((b=$1;b>=$i;b--))
do
  echo -n "*"
  done
  for((c=$1-1;c>=$i;c--))
do
  echo -n "*"
  done
echo ""
done

}

abc $1

22、使用shell 一键部署DNS正向解析

#!/bin/bash

#首先先判断检查磁盘是否挂载
df | grep "sr0"           #将过滤出来的sr0交给df查看是否已经挂载
if [ $? -eq 0 ];then      #如果挂载了
   yum install -y bind &>/dev/null    #就安装bind软件包
else                      #如果没有挂载
   mount /dev/sr0 /mnt    #先挂载磁盘
   yum install -y bind &>/dev/null    #然后再安装软件包
fi

#修改主配置文件:/etc/named.conf
sed -i 's/127.0.0.1/any/' /etc/named.conf
sed -i 's/localhost/any/' /etc/named.conf

#修改区域配置文件:/etc/named.rfc1912.zones
sed -i 's/localhost.localdamain/gcc.com/' /etc/named.rfc1912.zones
sed -i 's/named.localdamain/gcc.com.zone/' /etc/named.rfc1912.zones
sed -i '18,100d' /etc/named.rfc1912.zones

#修改区域数据文件:/etc/named/named.localhost
cd /var/named/
cp -p named.localhost gcc.com.zone
sed -i 's/@/gcc.com./g' /var/named/gcc.com.zone
sed -i 's/127.0.0.1/192.168.200.10/' /var/named/gcc.com.zone
sed -i '9a www IN A 192.168.200.10' /var/named/gcc.com.zone
sed -i '/AAAA/d' /var/named/gcc.com.zone

#添加指定DNS服务器
sed -i '1a nameserver 192.168.200.10' /etc/resolv.conf

#关闭防火墙
systemctl stop firewalld
setenforce 0

#开启DNS服务
systemctl restart named

23、使用免交互,一键进行PXE批量装机shell脚本

#!/bin/bash

#先磁盘判断是否挂载,并检查tftp和xinetd软件包是否安装
df | grep "sr0"
if [ $? -eq 0 ];then
  yum install -y tftp-server xinetd
else
  mount /dev/cdrom /mnt
  yum install -y tftp-server xinetd
fi

#修改TFTP服务的配置文件:/etc/xinetd.d/tftp
sed -i 's/yes/no/g'  /etc/xinetd.d/tftp    #将该配置文件中的no全部改成yes,以达到多台客户机一起安装和开启TFTP服务的目的

#开启TFTP服务
systemctl start tftp
systemctl enable tftp
systemctl start xinetd
systemctl enable xinetd

#安装并启用DHCP服务与ecpect
yum install -y dhcp expect 

#复制配置文件,进行免交互操作
/usr/bin/expect </etc/dhcp/dhcpd.conf </var/lib/tftpboot/pxelinux.cfg/default << ABC
default  auto          #指定默认入口名称
prompt 0               #设置是否等待用户选择, "1"表示等待用户控制,”0“表示不等待用户控制

label   auto           # 图形安装(默认)引导入口, label用来定义启动项
kernel vmlinuz         #kernel 和 append用来定义引导参数
append  initrd=initrd.img  method=ftp://192.168.200.10/centos7

label linux text       #文本安装引导入口
kernel  vmlinuz
append text initrd=initrd.img   method=ftp://192.168.200.10/centos7

label linux rescue      #救援模式引导入口
kernel vmlinuz
append  rescue initrd=initrd.img  method=ftp://192.168.200.10/centos7
ABC

#关闭防火墙
systemctl stop firewalld.service
setenforce 0

24、一键部署Apache服务

#!/bin/bash
systemctl stop firewalld
systemctl disable firewalld
setenforce 0

df | grep "sr0"   
if [ $? -eq 0 ];then
   yum -y install gcc gcc-c++ make pcre pcre-devel expat-devel perl &>/dev/null
else
   mount /dev/sr0 /mnt
   yum -y install gcc gcc-c++ make pcre pcre-devel expat-devel perl &>/dev/null
fi

read -p "请输入Apache源码包所在绝对路径:" a     #需要提前将apache的3个源码包上传到Linux中
cd $a
echo "----开始配置软件模块----"
tar zxvf apr-1.6.2.tar.gz &>/dev/null
tar zxvf apr-util-1.6.0.tar.gz &>/dev/null
tar jxvf httpd-2.4.29.tar.bz2 &>/dev/null

mv /opt/apr-1.6.2 /opt/httpd-2.4.29/srclib/apr
mv /opt/apr-util-1.6.0 /opt/httpd-2.4.29/srclib/apr-util

cd /opt/httpd-2.4.29/
./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi


make
make install

ln -s /usr/local/httpd/conf/httpd.conf /etc/httpd.conf
ln -s /usr/local/httpd/bin/* /usr/local/bin/

cd /lib/systemd/system
touch httpd.service

echo "[Unit]
Description=The Apache HTTP Server
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/httpd/logs/httpd.pid
ExecStart=/usr/local/bin/apachectl $OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target" >/lib/systemd/system/httpd.service

systemctl start httpd.service
systemctl enable httpd.service


b=$(sed -n '/IPADDR/p' /etc/sysconfig/network-scripts/ifcfg-ens33 | awk -F "=" '{print $2}')
sed -i 's/Listen 80/Listen $b:80/g' /etc/httpd.conf
sed -i 's/#ServerName www.example.com:80/ServerName www.benet.com:80/g'  /etc/httpd.conf


systemctl restart httpd.service

echo "$b www.benet.com" >> /etc/hosts

echo "apache服务已安装成功!"

25、一键部署MySQL脚本

#执行脚本之前需要先将MySQL所需的压缩包mysql-5.7.17.tar.gz和boost_1_59_0.tar.gz上传到/opt目录下
#!/bin/bash
systemctl stop firewalld
systemctl disable firewalld
setenforce 0

df | grep "sr0"   
if [ $? -eq 0 ];then
  yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake expect 
else
   mount /dev/sr0 /mnt
   yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake
fi

cd /opt
echo "----开始配置软件模块----"
tar zxvf mysql-5.7.17.tar.gz
tar zxvf boost_1_59_0.tar.gz

cd /opt
mv boost_1_59_0 /usr/local/boost

cd /opt/mysql-5.7.17/
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8  \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=/usr/local/boost \
-DWITH_SYSTEMD=1

make -j 2 && make install

useradd -M -s /sbin/nologin  mysql

#cd /etc
#touch my.cnf

echo "[client]
port = 3306
socket=/usr/local/mysql/mysql.sock			
[mysqld]
user = mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port = 3306
character-set-server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket=/usr/local/mysql/mysql.sock
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
" > /etc/my.cnf

chown -R mysql:mysql /usr/local/mysql/
chown mysql:mysql /etc/my.cnf

echo 'export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile	

source /etc/profile

cd /usr/local/mysql/bin/
./mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data

cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/

systemctl daemon-reload  
systemctl start mysqld.service
systemctl enable mysqld

yum -y install expect

function abc {
     
passwd=$1
/usr/bin/expect <<-EOF
spawn mysqladmin -u root -p password $passwd
expect "Enter password:" 
send "\r"

expect eof
EOF
}
abc "abc123"


function bcd {
     
/usr/bin/expect <<-EOF
spawn mysql -u root -p
expect "Enter password:" {
     send "abc123\r"}
expect "mysql>" {
     send "grant all privileges on *.* to 'root'@'%' identified by 'abc123';\r"}
expect "mysql>" {
     send "show databases;\r"}
expect "mysql>" {
     send "quit\r"}
expect eof
EOF
}
bcd

echo "MySQL数据库创建成功!"

26、使用脚本切割Nginx日志并收集

vim /opt/fengge.sh
#!/bin/bash
#rizhi fengge
day=$(date -d "-1 day" "+%Y%m%d")    #显示前一天时间
logs_path="/var/log/nginx"
pid_path="/usr/local/nginx/logs/nginx.pid"
[ -d $logs_path ] || mkdir -p $logs_path   #创建日志文件目录
mv /usr/local/nginx/logs/access.log ${
     logs_path}/gcc.com-access.log-$day   #移动并重命名日志文件
kill -USR1 $(cat $pid_path)      #重建新日志文件
find $logs_path -mtime +30 | xargs rm -rf   #删除30天之前的日志文件

chmod +x /opt/fengge.sh 
/opt/fengge.sh 
ls /var/log/nginx/
ls /usr/local/nginx/logs/access.log

crontab -e      #设置定时任务进行日志的分割收集
0 1 * * * /opt/fengge.sh

27、一键安装Nginx服务

#需提前将nginx-1.12.0.tar.gz压缩包上传到/opt目录下
#!/bin/bash
systemctl stop firewalld
systemctl disable firewalld
setenforce 0

df | grep "sr0"   
if [ $? -eq 0 ];then
   yum -y install gcc gcc-c++ pcre-devel zlib-devel make
else
   mount /dev/sr0 /mnt
   yum -y install gcc gcc-c++ pcre-devel zlib-devel make
fi

cd /opt
echo "----开始配置软件模块----"
tar zxvf nginx-1.12.0.tar.gz -C /opt/
cd nginx-1.12.0/

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

make -j 2 && make install

useradd -M -s /sbin/nologin nginx

ln -s /usr/local/nginx/sbin/* /usr/local/sbin/ 

cd /lib/systemd/system/
touch nginx.service
echo "[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
PIDFile =/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target" > /lib/systemd/system/nginx.service

chmod 754 /lib/systemd/system/nginx.service 
systemctl start nginx.service 
systemctl enable nginx.service 

echo "Nginx部署完成!!"

28、一键部署LNMP

#需提前将nginx-1.12.0.tar.gz、mysql-boost-5.7.20.tar.gz、php-7.1.10.tar.bz2压缩包上传到/opt目录下,创建好YUM源,挂载cdrom
#!/bin/bash
systemctl stop firewalld
systemctl disable firewalld
setenforce 0

yum -y install gcc gcc-c++ pcre-devel zlib-devel make

cd /opt
echo "开始配置Nginx......"
useradd -M -s /sbin/nologin nginx
tar zxvf nginx-1.12.0.tar.gz -C /opt/

cd nginx-1.12.0/
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module

make -j 2 && make install

ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/

echo '[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecrReload=/bin/kill -s HUP $MAINPID
ExecrStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target' > /lib/systemd/system/nginx.service

chmod 754 /lib/systemd/system/nginx.service 
systemctl start nginx.service 
systemctl enable nginx.service 

echo "Nginx部署完成!!"


echo "开始部署MySQL........."
yum -y install \
ncurses \
ncurses-devel \
bison \
cmake

useradd -M -s /sbin/nologin mysql

cd /opt
tar xzvf mysql-boost-5.7.20.tar.gz -C /opt

cd /opt/mysql-5.7.20/
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8  \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=boost \
-DWITH_SYSTEMD=1

make -j 2
make install

#修改mysql 配置文件
echo '[client]
port = 3306
socket=/usr/local/mysql/mysql.sock

[mysqld]
user = mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port = 3306
character-set-server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket=/usr/local/mysql/mysql.sock
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
server-id = 1

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES' > /etc/my.cnf

chown -R mysql:mysql /usr/local/mysql/
chown mysql:mysql /etc/my.cnf

echo "export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib">> /etc/profile	
source /etc/profile

cd /usr/local/mysql/bin/
./mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data

cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/ 
systemctl daemon-reload
systemctl start mysqld.service
systemctl enable mysqld


#修改mysql 的登录密码
yum -y install expect

function bcd {
     
/usr/bin/expect <<-EOF
passwd=$1
spawn mysqladmin -u root -p password $passwd 
expect "Enter password:" {
     send "\r"}
EOF
}
bcd "abc123"

function efg {
     
/usr/bin/expect <<-EOF
spawn mysql -u root -pabc123
expect "mysql>" {
     send "quit\t"}
EOF
}

#授权远程登录
#function bcd {
     
#/usr/bin/expect <<-EOF
#spawn mysql -u root -p
#expect "Enter password:" {
     send "abc123\r"}
#expect "mysql>" {
     send "grant all privileges on *.* to 'root'@'%' identified by 'abc123';\r"}
#expect "mysql>" {
     send "show databases;\r"}
#expect "mysql>" {
     send "quit\r"}
#expect eof
#EOF
#}
#bcd

echo -e "\033[31m mysql安装完成!\033[0m"


echo "开始部署PHP......"
yum -y install gd \
libjpeg libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel

cd /opt
tar jxvf php-7.1.10.tar.bz2 
cd php-7.1.10
./configure \
--prefix=/usr/local/php \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-mysqli \
--with-zlib \
--with-curl \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-openssl \
--enable-fpm \
--enable-mbstring \
--enable-xml \
--enable-session \
--enable-ftp \
--enable-pdo \
--enable-tokenizer \
--enable-zip

make 
make install

ln -s /usr/local/php/bin/* /usr/local/bin/

#修改PHP配置文件
#修改主配置文件
cp /opt/php-7.1.10/php.ini-development /usr/local/php/lib/php.ini
sed -i '1170c mysqli.default_socket = /usr/local/mysql/mysql.sock' /usr/local/php/lib/php.ini
sed -i '939c date.timezone = Asia/Shanghai' /usr/local/php/lib/php.ini

php -m 

#修改进程服务配置文件:php-fpm.conf
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
sed -i '17c pid = run/php-fpm.pid' /usr/local/php/etc/php-fpm.conf

#修改扩展配置文件:www.conf
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf

ln -s /usr/local/php/sbin/* /usr/local/sbin
/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
netstat -anpt | grep 9000

#配置 Nginx 支持 PHP 解析
#--65行--取消注释,修改
sed -i '65c location ~ \.php$ {' /usr/local/nginx/conf/nginx.conf
sed -i '66c root           html;' /usr/local/nginx/conf/nginx.conf
sed -i '67c fastcgi_pass   127.0.0.1:9000;' /usr/local/nginx/conf/nginx.conf
sed -i '68c fastcgi_index  index.php;' /usr/local/nginx/conf/nginx.conf
sed -i '69c fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;' /usr/local/nginx/conf/nginx.conf
sed -i '70c include        fastcgi_params;' /usr/local/nginx/conf/nginx.conf
sed -i '71c }' /usr/local/nginx/conf/nginx.conf

systemctl restart nginx.service

echo '<?php
phpinfo();
?>' > /usr/local/nginx/html/index.php
k=`ip a | grep "ens33" | awk 'NR==2{print$2}' | awk -F/ '{print$1}'`


#验证数据库工作是否正常
function hij {
     
/usr/bin/expect <<-EOF
spawn mysql -u root -p
expect "Enter" {
     send "\r"}
expect "mysql>" {
     send "CREATE DATABASE bbs;\r"}
expect "mysql>" {
     send "GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123';\r"}
expect "mysql>" {
     send "GRANT all ON bbs.* TO 'bbsuser'@'localhost' IDENTIFIED BY 'admin123';\r"}
expect "mysql>" {
     send "flush privileges;\r"}
expect "mysql>" {
     send "quit\r"}
EOF
}
hij

echo "PHP部署完成!!"

29、一键部署LAMP

#(需提前将所有软件包上传到/opt目录下)
#!/bin/bash

read -p "请输入你需要配置的域名(例:www.abc.com):" y
df -h | grep /mnt
if [ $? -ne 0 ];then 
  mount /dev/sr0 /mnt > /dev/null
else
  echo "镜像文件已挂载"
fi


systemctl stop firewalld
systemctl disable firewalld
setenforce 0

yum -y install gcc gcc-c++ make pcre pcre-devel expat-devel perl

cd /opt/
tar zxvf apr-1.6.2.tar.gz
tar zxvf apr-util-1.6.0.tar.gz
tar jxvf httpd-2.4.29.tar.bz2

mv apr-1.6.2 /opt/httpd-2.4.29/srclib/apr
mv apr-util-1.6.0 /opt/httpd-2.4.29/srclib/apr-util

cd /opt/httpd-2.4.29/
./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi

make && make install

ln -s /usr/local/httpd/conf/httpd.conf /etc/
ln -s /usr/local/httpd/bin/* /usr/local/bin/


echo '[Unit]
Description=The Apache HTTP Server			
After=network.target						
[Service]
Type=forking								
PIDFile=/usr/local/httpd/logs/httpd.pid		
ExecStart=/usr/local/bin/apachectl $OPTIONS	
ExecReload=/bin/kill -HUP $MAINPID			
[Install]
WantedBy=multi-user.target' > /lib/systemd/system/httpd.service




cp /etc/httpd.conf{
     ,.bak}

z=`ip a | grep "ens33" | awk 'NR==2{print}' | awk -F "/" '{print$1}' | awk -F " " '{print$2}'`

sed -i "51c Listen $z:80" /etc/httpd.conf.bak
sed -i '52 s/^/#/' /etc/httpd.conf.bak

sed -i '197d' /etc/httpd.conf.bak
sed -i "196a ServerName $y:80" /etc/httpd.conf.bak

cat /etc/httpd.conf.bak > /etc/httpd.conf




 
#sed -i "s/Listen 80/Listen 192.168.184.30:80/" /etc/httpd.conf
#sed -i 's/#ServerName www.example.com:80/ServerName www.lic.com:80/' /etc/httpd.conf

systemctl start httpd.service
netstat -anpt | grep 80
echo -e "\033[31m Apache安装完成!\033[0m"



#--------编译安装mysql 服务--------
#mysql-5.7.17.tar.gz
#boost_1_59_0.tar.gz
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
echo "进行安装mysql服务"
yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake

#配置软件模块
cd /opt
tar zxvf mysql-5.7.17.tar.gz
tar zxvf boost_1_59_0.tar.gz
cd /opt
mv boost_1_59_0 /usr/local/boost


cd /opt/mysql-5.7.17/
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8  \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=/usr/local/boost \
-DWITH_SYSTEMD=1

make 
make install

useradd -M -s /sbin/nologin mysql

echo '[client]
port = 3306
socket=/usr/local/mysql/mysql.sock

[mysqld]									
user = mysql       							
basedir=/usr/local/mysql

datadir=/usr/local/mysql/data

port = 3306									
character-set-server=utf8	

pid-file = /usr/local/mysql/mysqld.pid

socket=/usr/local/mysql/mysql.sock

bind-address = 0.0.0.0

skip-name-resolve							
max_connections=2048

default-storage-engine=INNODB				
max_allowed_packet=16M	
server-id = 1

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES' > /etc/my.cnf

chown -R mysql:mysql /usr/local/mysql/
chown mysql:mysql /etc/my.cnf




cd /usr/local/mysql/bin/
./mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data

#添加mysqld系统服务

cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/		#用于systemctl服务管理
source /etc/profile
systemctl daemon-reload         #刷新识别     
systemctl start mysqld.service  #开启服务
systemctl enable mysqld         #开机自启动
netstat -anpt | grep 3306       #查看端口

yum -y install expect


function abc {
     
passwd=$1
/usr/bin/expect <<-EOF
spawn mysqladmin -u root -p password $passwd
expect "Enter password:" 
send "\r"

expect eof
EOF
}
abc "abc123"


function bcd {
     
/usr/bin/expect <<-EOF
spawn mysql -u root -p
expect "Enter password:" {
     send "abc123\r"}
expect "mysql>" {
     send "grant all privileges on *.* to 'root'@'%' identified by 'abc123';\r"}
expect "mysql>" {
     send "show databases;\r"}
expect "mysql>" {
     send "quit\r"}
expect eof
EOF
}
bcd
echo -e "\033[31m mysql安装完成!\033[0m"


#--------编译安装PHP 解析环境--------
#安装GD库和GD库关联程序,用来处理和生成图片
yum -y install \
gd \
libjpeg libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel

#配置软件模块
cd /opt
tar jxvf php-7.1.10.tar.bz2
cd /opt/php-7.1.10/

./configure \
--prefix=/usr/local/php7 \
--with-apxs2=/usr/local/httpd/bin/apxs \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-config-file-path=/usr/local/php7 \
--with-mysqli \
--with-zlib \
--with-curl \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-openssl \
--enable-mbstring \
--enable-xml \
--enable-session \
--enable-ftp \
--enable-pdo \
--enable-tokenizer \
--enable-zip

#编译及安装
make && make install

#复制模版文件作为PHP 的主配置文件,并进行修改
cp /opt/php-7.1.10/php.ini-development /usr/local/php7/php.ini	

#在测试环境时使用php.ini-development文件,而在生产环境时使用php.ini-production文件

#修改1170行为mysqli.default_socket = /usr/local/mysql/mysql.sock
sed -i '1170d' /usr/local/php7/php.ini
sed -i '1169a mysqli.default_socket = /usr/local/mysql/mysql.sock' /usr/local/php7/php.ini

#939行--取消注释,修改时区
sed -i '939d' /usr/local/php7/php.ini
sed -i '938a date.timezone = Asia/Shanghai' /usr/local/php7/php.ini

#优化把PHP 的可执行程序文件放入路径环境变量的目录中便于系统识别
ln -s /usr/local/php7/bin/* /usr/local/bin/

php -m 			#查看PHP 加载了哪些模块

#修改httpd 服务的配置文件:/etc/httpd.conf,让apache支持PHP

#--393行下--插入以下内容
#AddType application/x-httpd-php .php
#AddType application/x-httpd-php-source .phps

cp /etc/httpd.conf{
     ,.bak1}
sed -i '393a AddType application/x-httpd-php .php' /etc/httpd.conf.bak1
sed -i '394a AddType application/x-httpd-php-source .phps' /etc/httpd.conf.bak1

#--256行--修改首页文件名设置
#DirectoryIndex index.html index.php
sed -i '256c DirectoryIndex index.html index.php' /etc/httpd.conf.bak1

cat /etc/httpd.conf.bak1 > /etc/httpd.conf


#验证php测试页
cd /usr/local/httpd/htdocs
mv index.html index.html.bak
echo '<?php
phpinfo();
?>' > /usr/local/httpd/htdocs/index.php

#修改完httpd配置文件后重启服务
systemctl restart httpd.service
systemctl restart httpd.service

#浏览器访问

echo -e "\033[31m php安装完成!\033[0m"

30、监控Linux缓存并清理脚本

#!/bin/bash
#Men分区内存总量 
mem_total=`free -m | awk 'NR==2' | awk '{print $2}'`

#Men分区当前剩余内存的大小 
mem_free=`free -m | awk 'NR==3' | awk '{print $4}'`

#Men分区当前已使用内存的大小 
mem_used=`free -m | grep Mem | awk '{print  $3}'`

if (($mem_used != 0)); then

#如果已被使用,则计算当前剩余free所占总量,表示为整数
mem_per=`free -m | awk '/Mem:/ {print int($3/($3+$4)*100)"%"}'`
mem_total=`free -m | awk '/Mem:/ {print int($3/($3+$4)*100)}'`
#设置监控日志监控内存使用情况
DATA="$(date -d "today" +"%Y-%m-%d-%H-%M") free percent is : $mem_per"
echo $DATA >> /var/log/mem_alarm.log

#当前剩余百分比与80%进行比较 ,超过80%进行缓存清理
if [ $mem_total -gt 80 ]; then
sync
echo 1 > /proc/sys/vm/drop_caches
echo 2 > /proc/sys/vm/drop_caches
echo 3 > /proc/sys/vm/drop_caches

else
echo "Don't have to clean up"

#将release memory OK !写入/var/log/文件夹的memstat_日期.log日志中
echo "--->release memory OK ! " >>/var/log/memstat_$(date +%Y%m%d_%H%M%S).log
fi
fi


你可能感兴趣的:(shell,运维,脚本,shell,脚本语言,运维)