Linux有哪些好用的网络脚本,Linux很多比较好用的shell脚本程序用于监控服务器状态查询一些信...

Linux很多比较好用的shell脚本程序用于监控服务器状态查询一些信

Linux很多比较好用的shell脚本程序用于监控服务器状态查询一些信息

查看linux系统信息

#!/bin/bash

#

#---------------------------------------

#Author: MartinHe

#Date: 2019-03-16

#FileName: systeminfo.sh

#URL: https://blog.51cto.com/5033330

#Desciption: The test Scirpt

#Copyright(c) 2019 All rights reserved

#---------------------------------------

export Start_Color="\e[1;32m"

export End_Color="\e[0m"

Ipaddr=`ifconfig | grep -Eo --color=auto "(\

-9]{2}|2[0-4][0-9]|25[0-5])\>\.){3}\

[0-4][0-9]|25[0-5])\>"| head -1`

Version=`cut -d" " -f4 /etc/redhat-release`

KerneVer=`uname -r`

Cpu_Info=`lscpu | grep "Model name:"|tr -s " " |cut -d: -f2`

Mem_Info=`free -mh|tr -s " "|cut -d" " -f2 |head -2| tail -1`

HD_Info=`lsblk | grep "^sd\{1,\}"| tr -s " "|cut -d" " -f1,4`

echo -e "The System Hostname is : $Start_Color `hostname` $End_Color"

echo -e "The System IP ADDER is : $Start_Color $Ipaddr $End_Color"

echo -e "The System Version is : $Start_Color $Version $End_Color"

echo -e "The System kerneVer is : $Start_Color $KerneVer $End_Color"

echo -e "The System Cpu_Info is :$Start_Color $Cpu_Info $End_Color"

echo -e "The System Mem_Info is : $Start_Color $Mem_Info $End_Color"

echo -e "The System HD_Info is : $Start_Color \n$HD_Info $End_Color"

disk.sh

unset Start_Color

unset End_Color

unset Ipaddr

unset Version

unset KerneVer

unset Cpu_Info

unset Mem_Info

unset HD_Info

b59bb4706dbe9bb4136827f876584dea.png

#!/bin/bash

#

#---------------------------------------

#Author: MartinHe

#Date: 2019-03-20

#FileName: argsum.sh

#URL: https://blog.51cto.com/5033330

#Desciption: The test Scirpt

#Copyright(c) 2019 All rights reserved

#---------------------------------------

if [ $# -lt 1 ];then

echo "At least one argument(must be file)."

exit 10

elif [ -e $1 ] && [ -f $1 ];then

Space_Line=`grep "^$" $1 | wc -l`

echo "the $1 has ${Space_Line} space line"

fi

53b35b53a560f730fd30942e143c06a1.png

#!/bin/bash

#

#---------------------------------------

#Author: MartinHe

#Date: 2019-03-20

#FileName: checkdisk.sh

#URL: https://blog.51cto.com/5033330

#Desciption: The test Scirpt

#Copyright(c) 2019 All rights reserved

#---------------------------------------

Use_disk=`df |grep "^/dev/sd"| grep -Eo "\%"|tr -d %|sort -nr

|head -1`

[ $Use_disk -ge 17 ] && wall "space will full"

bb30699861f3437ca0fb1cd048e4d046.png

ping -c1 -W1 $1 &> /dev/null && echo "$1 is up" || echo "$1 is donw"

显示两个文件空行的和

#!/bin/bash

#

#---------------------------------------

#Author: MartinHe

#Date: 2019-03-19

#FileName: sumspace.sh

#URL: https://blog.51cto.com/5033330

#Desciption: The test Scirpt

#Copyright(c) 2019 All rights reserved

#---------------------------------------

if [ $# -lt 2 ];then

echo "Usage: sumspace.sh /PATH/TO/SOMEFILE /PATH/TO/SOMEFILE"

exit 10

elif [ $# -gt 2 ];then

echo "two argument only."

exit 20

else

FILE1=`grep "^$" $1|wc -l`

FILE2=`grep "^$" $2|wc -l`

SPACE_SUM=$[$FILE1+$FILE2]

echo "The Space SUM is: $SPACE_SUM."

fi

c881dc9689e1e410b1844f6dda75cad6.png

选择YES or NO

#!/bin/bash

#

#---------------------------------------

#Author: MartinHe

#Date: 2019-03-20

#FileName: yesorno.sh

#URL: https://blog.51cto.com/5033330

#Desciption: The test Scirpt

#Copyright(c) 2019 All rights reserved

#---------------------------------------

read -p "Do you agree?(yes or NO):" ANS

ans1=`echo $ANS | grep -E -i "^[y]([e][s])?$"|tr [:upper:] [:lower:]`

ans2=`echo $ANS | grep -E -i "^[n][o]$"|tr [:upper:] [:lower:]`

if [ "$ans1" = "yes" ];then

echo "It's ok"

exit

elif [ "$ans2" = "no" ];then

echo "It's not ok"

exit

else

echo "Wrong input"

fi

9760bae64a0db14c3e93f5e607dea538.png

DIR=/data/script36/workdir/

cd $DIR

END=log

BC="\e[1;"

EC="\e[0m"

for file in *;do

file_name=`echo $file | sed -r '[email protected]^(.*)\..*[email protected]\[email protected]'`

mv $file ${file_name}.$END

echo -e "${BC}31m $file $EC is rename ${BC}35m ${file_name}.$END $EC success"

done

监控http服务运行状况(while)

#!/bin/bash

#

#---------------------------------------

#Author: MartinHe

#Date: 2019-04-09

#FileName: monitor.httpd_while.sh

#URL: https://blog.51cto.com/5033330

#Desciption: The test Scirpt

#Copyright(c) 2019 All rights reserved

#---------------------------------------

SLEEPING=20

SERVICE=httpd

LOG=/var/log/monitor_$SERVICE.log

while true;do

if killall -0 $SERVICE &> /dev/null;then

true

else

systemctl restart $SERVICE

echo "AT `date +'%F %T'` $SERVICE restart" | tee -a $LOG | mail -s "warning $SERVICE" root

fi

sleep $SLEEPING

done

根据访问lastb,禁止10次以上ip访问(while)

#!/bin/bash

#

#---------------------------------------

#Author: MartinHe

#Date: 2019-04-10

#FileName: denyip_while.sh

#URL: https://blog.51cto.com/5033330

#Desciption: The test Scirpt

#Copyright(c) 2019 All rights reserved

#---------------------------------------

LOG=cat /data/script36/ss.log | sed -nr '/^ESTAB/[email protected]* ([0-9.]+):[0-9]+.* ([0-9.]+):[0-9]+.*[email protected]\[email protected]'| sort | uniq -c

cat $LOG | while read num ip;do

if [ $num -gt 10 ];then

iptables -A INPUT -s $ip -j REJECT

fi

done

转载 https://blog.51cto.com/5033330/2367417

Linux很多比较好用的shell脚本程序用于监控服务器状态查询一些信相关教程

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值