1、显示统计占用系统内存最多的进程,并排序。
方法一:
[root@centos7 scripts43]#ps -eo pid,ppid,cmd,%mem,%cpu --sort -%mem|head -6
PID PPID CMD %MEM %CPU
7715 /usr/bin/gnome-shell 10.7 0.4
7715 /usr/bin/gnome-software --g 3.2 0.1
6799 /usr/bin/X :0 -background n 2.9 0.0
7715 nautilus-desktop --force 1.3 0.0
1 /usr/libexec/goa-daemon 1.3 0.0
方法二:
命令:top
使用M 对进程按照内存从大到小排序
2、编写脚本,使用for和while分别实现192.168.0.0/24网段内,地址是否能够ping通,若ping通则输出"success!",若ping不通则输出"fail!"
配置临时ip:
[root@centos7 ~]#ip a a dev eth0 label eth0:1 192.168.0.4/24
[root@centos6 ~]#ip a a dev eth0 label eth0:1 192.168.0.3/24编辑for脚本:
vim for_ping.sh
#!/bin/bash for ((i=1;i<255;i++));do { if ping -c1 -W2 "192.168.0.${i}" &> /dev/null ; then echo 192.168.0.${i} success! >>ping_resault.txt else echo 192.168.0.${i} fail! >>ping_resault.txt fi } done
for运行结果:
编辑while脚本:
vim while_ping.sh
#!/bin/bash declare -i i=1 while [ $i -lt 255 ];do { if ping -c1 -W1 "192.168.0.${i}" &> /dev/null ; then echo 192.168.0.${i} success! >>ping_resault_while.txt else echo 192.168.0.${i} fail! >>ping_resault_while.txt fi i+=1 } done
while运行结果:
3、每周的工作日1:30,将/etc备份至/backup目录中,保存的文件名称格式 为“etcbak-yyyy-mm-dd-HH.tar.xz”,其中日期是前一天的时间
1)写计划任务脚本:
vim /data/scripts43/crontab/crontab.sh
#!/bin/bash tar cvf /data/etcbak-\`date -d yesterday +%F-%T\`.tar.xz /etc/
脚本赋权限:
[root@centos7 data]#chmod u+x /data/scripts43/crontab/crontab.sh脚本运行结果:
[root@centos7 data]# tar cvf /data/etcbak-`date -d yesterday +%F-%T`.tar.xz /etc/2)添加到crontab计划任务中:
[root@centos7 data]#crontab -e
30 1 1-5 /data/scripts43/crontab/crontab.sh
4、工作日时间,每10分钟执行一次磁盘空间检查,一旦发现任何分区利用率高 于80%,就发送邮件报警
1)写脚本:
vim /data/scripts43/crontab/diskwall.sh#!/bin/bash PRE=80 NUM=`df |sed -nr '/^\/dev\/sd/s#.* ([0-9]+)%.*#\1#p' | sort -nr |head -1` [ "$NUM" -gt "$PRE" ] && wall disk will be full
赋权限:[root@centos7 data]#chmod u+x /data/scripts43/crontab/diskwall.sh
脚本运行结果:
2)添加到计划任务中:
[root@centos7 data]#crontab -e
/10 * /data/scripts43/crontab/diskwall.sh
架构班小伙伴看这里:
1、使用docker安装部署jumpserver跳板机
2、openstack rocky版keystone,glance,nova,neutron,cirros等安装配置。
3、配置nginx反向代理tomcat,并使用redis实现会话保持