运维开发网

Linux学习-第11周

运维开发网 https://www.qedev.com 2021-02-23 14:07 出处:51CTO 作者:水云间学习
1、显示统计占用系统内存最多的进程,并排序[[email protected]~]#psaxouser,cmd,%memk-%mem|head-n20USERCMD%MEMroot/usr/libexec/sssd/sssd_nss1.9root/usr/libexec/platform-pytho1.6polkitd/usr/lib/polkit-1/polkitd-1.4apache/usr/sbin/

1、显示统计占用系统内存最多的进程,并排序

[[email protected] ~]#ps axo user,cmd,%mem k -%mem |head -n20

USER CMD %MEM

root /usr/libexec/sssd/sssd_nss 1.9

root /usr/libexec/platform-pytho 1.6

polkitd /usr/lib/polkit-1/polkitd - 1.4

apache /usr/sbin/httpd -DFOREGROUN 1.0

apache /usr/sbin/httpd -DFOREGROUN 1.0

apache /usr/sbin/httpd -DFOREGROUN 1.0

root /usr/sbin/NetworkManager -- 0.9

root /usr/libexec/sssd/sssd_be - 0.7

root /usr/sbin/httpd -DFOREGROUN 0.7

root /usr/sbin/sssd -i --logger= 0.7

root /usr/sbin/ModemManager 0.6

root /usr/bin/vmtoolsd 0.5

root /usr/lib/systemd/systemd -- 0.5

root /usr/bin/VGAuthService -s 0.5

root sshd: root [priv] 0.5

root /usr/lib/systemd/systemd-ud 0.5

root /usr/sbin/cupsd -l 0.5

root /usr/sbin/rsyslogd -n 0.4

root /usr/lib/systemd/systemd -- 0.4

2、编写脚本,使用for和while分别实现192.168.0.0/24网段内,地址是否能够ping通,若ping通则输出'success',若ping不通则输出'fail'

(1) for循环

[[email protected] test]#cat scanhost.sh

#!/bin/bash

NET=192.168.0

for i in {1..254};do

(

ping -c1 -W1 ${NET}.${i} &> /dev/null && echo ${NET}.${i} : success || echo ${NET}.${i} :fail

)&

done

wait

(2) while循环

[[email protected] test]#cat scanhost2.sh

#!/bin/bash

NET=192.168.0

i=1

while [ $i -lt 255 ];do

(

ping -c1 -W1 ${NET}.${i} &> /dev/null && echo ${NET}.${i} : success || echo ${NET}.${i} :fail

)&

let i++

done

wait

3、每周的工作日1:30,将/etc备份至/backup目录中,保存的文件名称格式为"etcbak-yyy-mm-dd-HH.tar.xz",其中日期是前一天的时间

[[email protected] backup]#crontab -l

30 1 0 /usr/bin/tar Jcf /backup/etcback-(date +\%F-\%H -d '-1 day').tar.xz /data/test

4、工作日时间,每10分钟执行一次磁盘空间检查,一旦发现任何分区利用率高于80%,就发送邮件报警

[[email protected] backup]#cat /data/test/disk_check.sh

#!/bin/bash

WARNING=80

df |awk -F" +|%" '/^\/dev\/sd/{print $1,$5}' | while read DEVICE USED ;do

[ $USED -gt $WARNING ] && echo "$DEVICE will be full! Usage is $USED" | mail -s diskfull root

done [[email protected] backup]#crontab -l

*/10 * * * 1-5 /data/test/diskcheck.sh

扫码领视频副本.gif

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号