#!/bin/bash
#
#********************************************************************
#Author: zhouyafei
#Date: 2018-04-18
#FileName: systeminfo.sh
#Description: The test script
#Copyright (C): 2018 All rights reserved
#********************************************************************
echo “The CPU of the system is:” `lscpu |grep “name” |tr -s ” ” |cut -d ” ” -f 5`
echo “The memory size of the system is:” `free -h |grep “Swap” |tr -s ” ” |cut -d” ” -f 2`
echo “The size of the system’s hard disk is :” `lsblk |grep -w “sda” |tr -s ” ” |cut -d ” ” -f 4`
echo “The system version is :” `cat /etc/centos-release |grep -o ” [0-9]”`
echo “The kernel version is :” `uname -r`
echo “The name of the system host :” `hostname`
echo “The IP of the system is :” `ifconfig ens33 |sed -n “2p” |sed “s/.*inet//” |sed “s/net.*//”`
#!/bin/bash
#
#********************************************************************
#Author: zhouyafei
#Date: 2018-04-18
#FileName: backup.sh
#Description: The test script
#Copyright (C): 2018 All rights reserved
#********************************************************************
echo -e “\e[1;31mStart a backup…\e[0m”
sleep 5
cp -av /etc/ /data/etc`date “+%F”`
echo -e “\e[1;33mBackup completion\e[0m”
3、编写脚本/root/bin/disk.sh,显示当前硬盘分区中空间利用率最大的值
#!/bin/bash
#
#********************************************************************
#Author: zhouyafei
#Date: 2018-04-18
#FileName: disk.sh
#Description: The test script
#Copyright (C): 2018 All rights reserved
#********************************************************************
echo “The maximum value of the hard disk is :” `df |grep “sda” |tr -s ” ” |cut -d” ” -f 5 |sort -nr |head -n1`
#!/bin/bash
#
#********************************************************************
#Author: zhouyafei
#Date: 2018-04-18
#FileName: hostping.sh
#Description: The test script
#Copyright (C): 2018 All rights reserved
#********************************************************************
[[ $1 =~ “\<(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>” ]] && echo “Please enter a correct IP” && exit
ping -c1 $1>/dev/null && echo “The IP can be accessed” || echo “The IP is not accessible”
#!/bin/bash
#
#********************************************************************
#Author: zhouyafei
#Date: 2018-04-18
#FileName: checkdisk.sh
#Description: The test script
#Copyright (C): 2018 All rights reserved
#********************************************************************
disk=`df |grep “sda”|tr -s ” ” “%” |cut -d”%” -f 5 |sort -nr |head -n1`
[ “$disk” -ge 40 ] && echo “The use rate of disk partitions is now :” $disk && wall Space will be full
#!/bin/bash
#
#********************************************************************
#Author: zhouyafei
#Date: 2018-04-18
#FileName: per.sh
#Description: The test script
#Copyright (C): 2018 All rights reserved
#********************************************************************
[ $# -ne 1 ] && echo “You have to enter one” && exit
[ ! -r $1 -a -w $1 ] && echo “The document is unreadable and cannot be written.” || echo “Read and write permissions to the file”
#!/bin/bash
#
#********************************************************************
#Author: zhouyafei
#Date: 2018-04-18
#FileName: nologin.sh
#Description: The test script
#Copyright (C): 2018 All rights reserved
#********************************************************************
[ -a /etc/nologin ] && echo “The nologin file exists! “|| (touch /etc/nologin; echo -e “\e[1;31mThe nologin file is created!\e[0m “;)
删除nologin文件
#!/bin/bash
#
#********************************************************************
#Author: zhouyafei
#Date: 2018-04-18
#FileName: login.sh
#Description: The test script
#Copyright (C): 2018 All rights reserved
#********************************************************************
[ -a /etc/nologin ] && echo -e `rm -f /etc/nologin` -e “\e[1;31mThe file has been deleted!\e[0m” || echo “The file does not exist”