标签搜索

shell sh 使用汇总

sunshine
2023-08-29 / 0 评论 / 53 阅读
温馨提示:
本文最后更新于2023年08月29日,已超过375天没有更新,若内容或图片失效,请留言反馈。

数据库备份

#!/bin/bash
/home/soft/mysql-5.7.36/bin/mysqldump -uxxxx -P3307 -h 127.0.0.1 -pxxxx sunshine2 | gzip > /home/backup/sunshine_$(date +%Y%m%d).sql.gz

black.sh 防止恶意登录

#!/bin/bash
cat /var/log/secure|awk '/Failed/{print $(NF-3)}'|sort|uniq -c|awk '{print $2"="$1;}' > /root/black.txt
DEFINE="10"
for i in `cat /root/black.txt`
do
    IP=`echo | awk '{split("'${i}'",array,"=");print array[1]}'`
    NUM=`echo | awk '{split("'${i}'",array,"=");print array[2]}'`
    if [ $NUM -gt $DEFINE ];then
      grep $IP /etc/hosts.deny > /dev/null
        if [ $? -gt 0 ];then
          echo "sshd:$IP:deny" >> /etc/hosts.deny
        fi
    fi
done

清理释放内存

#!/bin/bash
Mem=$(free -m | awk 'NR==2' | awk '{print $4}')
if [ $Mem -gt 1024 ];
    then
echo "Service memory capacity is normal" > /dev/null
    else
sync
echo "1" > /proc/sys/vm/drop_caches
echo "2" > /proc/sys/vm/drop_caches
echo "3" > /proc/sys/vm/drop_caches
sync
fi

nginx

#!/bin/bash
if [[ -z $1 ]];then
        echo -e "\033[32m输入格式:$0 stop|star|reopen|reload\033[0m"
        exit;
fi
case $1 in
reload )
/home/soft/nginx/sbin/nginx -s reload
;;
stop )
/home/soft/nginx/sbin/nginx -s stop
;;
start )
/home/soft/nginx/sbin/nginx
;;
reopen )
/home/soft/nginx/sbin/nginx -s stop && /home/soft/nginx/sbin/nginx
;;
test )
/home/soft/nginx/sbin/nginx -t
;;
* )
echo "invalid params"
;;
esac
if [ $? == 0 ];then
        echo -e "\033[32mnginx $1 success !\033[0m"
fi

redis

#!/bin/bash
cd /home/soft/redis-6.2.6
nohup redis-server /home/soft/redis-6.2.6/etc/redis-6350.conf > start.log 2>&1 &
echo -e "\033[32m redis is running ... \033[0m";
感觉很棒,欢迎点赞 OR 打赏~
1
分享到:

评论 (0)

取消