1、显示统计占用系统内存最多的进程,并排序。
[22:32:52 root@bear ~]#ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem
PID PPID CMD %MEM %CPU
1540 1523 /usr/bin/gnome-shell 12.2 0.1
1615 1 /usr/libexec/ibus-x11 --kil 3.0 0.0
1353 1 /usr/sbin/libvirtd 2.3 0.0
1583 1540 /usr/bin/Xwayland :1024 -ro 2.3 0.0
992 1 /usr/libexec/platform-pytho 2.0 0.0
989 920 /usr/libexec/sssd/sssd_nss 1.9 0.0
1118 1 /usr/libexec/platform-pytho 1.6 0.0
3616 1 /usr/libexec/packagekitd 1.4 0.4
1692 1523 /usr/libexec/gsd-media-keys 1.4 0.0
1678 1523 /usr/libexec/gsd-color 1.3 0.0
924 1 /usr/lib/polkit-1/polkitd - 1.3 0.0
....
2、编写脚本,使用for和while分别实现192.168.0.0/24网段内,地址是否能够ping通,若ping通则输出"success!",若ping不通则输出"fail!"
[23:39:01 root@bear data]#cat for_scenip.sh
#!/bin/bash
#
#********************************************************************
#Author: stella tang
#Mail: 359564666@126.com
#Date: 2021-02-28
#FileName: for_scenip.sh
#URL: https://jianshu.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
NET=192.168.0
for ID in {1..254}; do
{ ping -c1 -w1 $NET.$ID &> /dev/null && echo "success !" || echo "fail !"
}&
done
wait
[23:38:57 root@bear data]#bash for_scenip.sh
fail !
fail !
fail !
fail !
fail !
fail !
fail !
fail !
fail !
fail !
fail !
fail !
[00:02:17 root@bear data]#cat while_scanip.sh
#!/bin/bash
#
#********************************************************************
#Author: stella tang
#Mail: 359564666@126.com
#Date: 2021-02-28
#FileName: while_scanip.sh
#URL: https://jianshu.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
NET=192.168.0.
declare -i ID=1
while [ $ID -le 255 ];do
{ if ping -c1 -w1 $NET$ID > /dev/null; then
echo "sucess!"
else
echo "fail!"
fi }&
let ID++
done
wait
[00:02:09 root@bear data]#bash while_scanip.sh
fail!
fail!
fail!
fail!
fail!
fail!
fail!
fail!
fail!
fail!
fail!
fail!
fail!
fail!
....
3、每周的工作日1:30,将/etc备份至/backup目录中,保存的文件名称格式 为“etcbak-yyyy-mm-dd-HH.tar.xz”,其中日期是前一天的时间
[23:11:50 root@bear ~]#cat etcback.sh
#!/bin/bash
#
#********************************************************************
#Author: stella tang
#Mail: 359564666@126.com
#Date: 2021-02-28
#FileName: etcback.sh
#URL: https://jianshu.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
[ -d /data/backup ] || mkdir -p /data/backup
tar -zcPf /data/backup/etcback-`date -d -1day +%F-%H`.tar.gz /etc/ > /dev/null
[22:59:16 root@bear ~]#crontab -l
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
30 1 * * 1-5 /root/etcbackup.sh
4、工作日时间,每10分钟执行一次磁盘空间检查,一旦发现任何分区利用率高 于80%,就发送邮件报警
[23:18:08 root@bear data]#cat diskcheck.sh
#!/bin/bash
#
#********************************************************************
#Author: stella tang
#Mail: 359564666@126.com
#Date: 2021-02-28
#FileName: diskcheck.sh
#URL: https://jianshu.com
#Description: The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
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 root
done
[23:21:18 root@bear data]#crontab -l
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
#30 1 * * 1-5 /root/etcbackup.sh
*/10 * * * 1-5 /data/diskcheck.sh