1育特、顯示統(tǒng)計占用系統(tǒng)內(nèi)存最多的進程,并排序先朦。
[root@localhost ~]# ps axo pid,cmd,%cpu,%mem --sort -%mem
PID CMD %CPU %MEM
5516 /opt/py3/bin/python3.6 /opt 0.0 1.8
5514 /opt/py3/bin/python3.6 /opt 0.0 1.7
5510 /opt/py3/bin/python3.6 /opt 0.0 1.7
5546 /opt/py3/bin/python3.6 /opt 0.1 1.7
5512 /opt/py3/bin/python3.6 /opt 0.0 1.6
5561 /opt/py3/bin/python3.6 /opt 0.0 1.6
5518 /opt/py3/bin/python3.6 /opt 0.2 1.6
5534 /opt/py3/bin/python3.6 /opt 0.2 1.6
5562 /opt/py3/bin/python3.6 /opt 0.0 1.6
2776 /usr/libexec/mysqld --based 0.1 1.6
5538 /opt/py3/bin/python3.6 /opt 0.0 1.6
5556 /opt/py3/bin/python3.6 /opt 0.0 1.5
5557 /opt/py3/bin/python3.6 /opt 0.0 1.5
缰冤。犬缨。。棉浸。怀薛。。
2迷郑、編寫腳本乾戏,使用for和while分別實現(xiàn)192.168.0.0/24網(wǎng)段內(nèi),地址是否能夠ping通三热,若ping通則輸出"success!"鼓择,若ping不通則輸出"fail!"
#for循環(huán)
[root@localhost ~]# cat for_ping.sh
#!/bin/bash
NET=192.168.0
for ID in {1..254};do
{
ping -c1 -W1 $NET.$ID &> /dev/null && echo $NET.$ID "success!" || echo $NET.$ID "fail!"
}&
done
wait
#while循環(huán)
[root@localhost ~]# cat while_ping.sh
#!/bin/bash
NET=192.168.0.
declare -i Id=1
while [ $Id -le 254 ];do
{
ping -c1 -W1 $NET$Id > /dev/null
if [ $? -eq 0 ];then
echo "$NET$Id success!"
else
echo "$NET$Id fail!"
fi
} &
let Id++
done
wait
3、每周的工作日1:30就漾,將/etc備份至/backup目錄中呐能,保存的文件名稱格式 為“etcbak-yyyy-mm-dd-HH.tar.xz”,其中日期是前一天的時間
[root@localhost ~]# cat etcbackup.sh
#!/bin/bash
[ -d /backup ] || mkdir /backup
/usr/bin/tar -JcPf /backup/etcbak-`date -d -1day +%F-%H`.tar.xz /etc/ > /dev/null
[root@localhost ~]# crontab -l
30 1 * * 1-5 /bin/bash /root/etcbackup.sh
[root@localhost ~]# ll /backup/
總用量 13704
-rw-r--r-- 1 root root 7012436 2月 5 13:48 etcbak-2021-02-04-13.tar.xz
-rw-r--r-- 1 root root 7012436 2月 5 14:00 etcbak-2021-02-04-14.tar.xz
4抑堡、工作日時間摆出,每10分鐘執(zhí)行一次磁盤空間檢查,一旦發(fā)現(xiàn)任何分區(qū)利用率高 于80%首妖,就發(fā)送郵件報警
#配置郵箱
[root@localhost ~]# cat .mailrc
set from=1787183478@qq.com
set smtp=smtp.qq.com
set smtp-auth-user=1787183478@qq.com
set smtp-auth-password=pzzxrfltahtudddh
set smtp-auth=login
set ssl-verify=ignore
[root@localhost ~]# cat diskcheck.sh
#!/bin/bash
WARNING=80
df | sed -En '/^\/dev\/sd/s@^([^ ]+).* ([0-9]+)%.*@\1 \2@p'| while read DEVICE USE;
do
[ $USE -gt $WARNING ] && echo "$DEVICE will be full,USE:$USE" | mail -s "diskfull" 1787183478@qq.com
done
[root@localhost ~]# crontab -l
*/10 * * * 1-5 /bin/bash /root/diskcheck.sh