1、顯示統(tǒng)計(jì)占用系統(tǒng)內(nèi)存最多的進(jìn)程三圆,并排序。
ps -aux --sort=-%mem
2避咆、編寫腳本舟肉,使用for和while分別實(shí)現(xiàn)192.168.0.0/24網(wǎng)段內(nèi),地址是否能夠ping通查库,若ping通則輸出"success!"路媚,若ping不通則輸出"fail!"
for循環(huán):
#!/bin/bash
ip_first="192.168.0."
for i in {1...154}
do
ping -c 1 $ip_first$i &>/dev/null
if [ $? -eq 0 ];then
????echo "$ip_pre.$i success!"
? else
????echo "$ip_pre.$i fail!"
done
while循環(huán):
#!/bin/bash
ip_pre=192.168.0.
i=1
while [ $i -lt 255 ]
do
????ping -c1 $ip_pre$i &> /dev/null
????if [ $? -eq 0 ];then
??????echo "$ip_pre.$i success!"
????else
??????echo "$ip_pre.$i fail!"
????fi
????let i++
done
3、每周的工作日1:30樊销,將/etc備份至/backup目錄中整慎,保存的文件名稱格式 為“etcbak-yyyy-mm-dd-HH.tar.xz”脏款,其中日期是前一天的時(shí)間
備份:
#!/bin/bash
tar cpvf etcbak-`date -d yesterday "+%F-%d-%H" `.tar.xz /etc
if [ $? -eq 0 ];then
??????mv etcbak-`date "+%F-%d-%H"`.tar.xz /backup???
fi
設(shè)置定時(shí)任務(wù)
echo "30 01 * * * sh bask.sh" >>/etc/crontab
4、工作日時(shí)間裤园,每10分鐘執(zhí)行一次磁盤空間檢查撤师,一旦發(fā)現(xiàn)任何分區(qū)利用率高 于80%,就發(fā)送郵件報(bào)警
#!/bin/bash
DISK=`df | grep "^/dev/sd.*" | sed -nr 's@^.* ([0-9]+)%.*$@\1@p'`
if [ $DISK -ge 80 ];then
wall disk space Used warning
else
exit
fi
設(shè)置定時(shí)任務(wù)
echo "10 * * * * sh bask.sh" >>/etc/crontab