1、显示统计占用系统内存最多的进程,并排序。
[root@localhost ~]# ps aux | awk '{print $1,$2,$4,$11}'| sort -rn -k 3 -t " " root 1190 1.0 /usr/bin/python2 polkitd 959 0.7 /usr/lib/polkit-1/polkitd root 969 0.6 /usr/sbin/NetworkManager root 1449 0.4 sshd: root 1193 0.3 /usr/sbin/rsyslogd root 1192 0.3 /usr/sbin/sshd postfix 1281 0.3 qmgr postfix 1280 0.3 pickup root 712 0.2 /usr/lib/systemd/systemd-journald root 1279 0.2 /usr/libexec/postfix/master root 1 0.2 /usr/lib/systemd/systemd dbus 961 0.2 /usr/bin/dbus-daemon root 972 0.1 /usr/sbin/crond root 955 0.1 /usr/lib/systemd/systemd-logind root 931 0.1 /sbin/auditd root 743 0.1 /usr/lib/systemd/systemd-udevd root 739 0.1 /usr/sbin/lvmetad root 1508 0.1 sort root 1506 0.1 ps root 1451 0.1 -bash
2、编写脚本,使用for和while分别实现192.168.0.0/24网段内,地址是否能够ping通,若ping通则输出"success!",若ping不通则输出"fail!"
[root@localhost ~]# vsh ping_for.sh #!/bin/bash #Description: #Author:root #Version:1.0 #CreateTime:2021-05-28 11:37:27 net=192.168.0. for i in {1..255};do { ping $net$i -c 2 -w 3 &> /dev/null if [ $? -eq 0 ] then echo "$net$i is success" else echo "$net$i is fail" fi }& done wait [root@localhost ~]# vsh ping_while.sh #!/bin/bash #Description: #Author:root #Version:1.0 #CreateTime:2021-05-28 13:13:00 net=192.168.0. i=1 while [ $i -le 255 ] do { ping -c 1 -w 1 $net$i &> /dev/null if [ $? -eq 0 ] then echo "$net$i is success " else echo "$net$i is fail" fi }& let i++ done
3、每周的工作日1:30,将/etc备份至/backup目录中,保存的文件名称格式 为“etcbak-yyyy-mm-dd-HH.tar.xz”,其中日期是前一天的时间
[root@localhost ~]# vsh cp_etc.sh #!/bin/bash #Description: #Author:root #Version:1.0 #CreateTime:2021-05-28 11:45:41 [ -d /backup ] || mkdir /backup time=`date -d "-1 day" +"%F-%H"` tar -Jcvf /backup/etcbak-$time.tar.xz /etc crontab -e 30 13 * * 1-5 /bin/bash /root/cp_etc.sh
4、工作日时间,每10分钟执行一次磁盘空间检查,一旦发现任何分区利用率高 于80%,就发送邮件报警
[root@localhost ~]# vsh check_disk.sh 1 #!/bin/bash 2 #Description: 3 4 #Author:root 5 #Version:1.0 6 #CreateTime:2021-05-28 12:14:07 7 disk=`df -h | awk '{print $5}'|sort -n|tail -1|sed -e 's/%//'` 8 if [ $disk -gt 80 ] 9 then 10 echo -e "disk usage is exceeds 80% "|mail -s waring root 11 fi [root@localhost ~]# crontab -e */10 * * * 1-5 /bin/bah /root/check_disk.sh