Text Three Musketeers

1. Display and sort the processes that occupy the most system memory.
ps aux | grep -v PID | sort -rn -k +4 | head
Text Three Musketeers
2. Write a script, use for and while to realize whether the address can be pinged within the 192.168.0.0/24 network segment, if ping is successful, output "success! ", If ping fails, output" fail! "
1.for loop implementation
#! / Bin / bash

NETID=192.168.0
for HOSTID in {1..254};do
{
ping -c1 -W1 $NETID.$HOSTID &> /dev/null
if [ $? -eq 0 ];then
echo "$NETID.$HOSTID success!"
else
echo "$NETID.$HOSTID fail!"
fi
} &
done
Text Three Musketeers
2.while循环实现
#!/bin/bash

NETID=192.168.214
declare -i HOSTID=1

while [ $HOSTID -lt 255 ];do

ping -c1 -W1 $NETID.$HOSTID &> /dev/null

if [ $? -eq 0 ];then
echo "$NETID.$HOSTID success!"
else
echo "$NETID.$HOSTID fail!"
fi

let HOSTID++

done
3. At 1:30 every weekday, backup / etc to the / backup directory, the file name format saved is "etcbak-yyyy-mm-dd-HH.tar.xz", where the date is the day before time

[root@centos7 ~]# crontab -e
30 1 1-5 /usr/bin/tar -Jcf etcbak-date -d "-1 day" +%Y-%m-%d-%H.tar.xz /etc &> /dev/null

4. During the working day, a disk space check is performed every 10 minutes. Once any partition utilization rate is higher than 80%, an email alarm is sent

  1. Prepare the alarm script first
    [root @ centos7 data] # vim while_checkdisk.sh
    #! / Bin / bash

WARNING=10
MAIL=root@localhost

df |sed -rn '/^\/dev\/sd/s#^([^[:space:]]+). ([[:digit:]]+)%.#\1 \2#p'|while read diskpart used;do

if [ $used -gt $WARNING ];then
echo $diskpart will be full,used:$used% | mail -s "diskcheck_alert" $MAIL
fi
done

  1. Add execute permission to the script
    chmod + x while_checkdisk.sh
  2. Add timed task
    crontab -e
    / 10 * / bin / bash /data/while_checkdisk.sh &> / dev / null

Guess you like

Origin blog.51cto.com/14671983/2486597