第十一周作业
1、显示统计占用系统内存最多的进程,并排序。
[12:34:24 root@localhost ~]#ps aux --sort -rss |head -7
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
systemd+ 1307 1.6 7.3 1576880 223992 pts/2 Ssl+ 12:33 0:01 mysqld
root 3218 12.1 5.5 759684 168788 ? Sl 12:33 0:04 /opt/py3/bin/python3.8 /opt/py3/bin/celery worker -P threads -A ops -l INFO -c 10 -Q ansible -n ansible@%h
root 3516 9.2 5.3 972856 160768 ? Sl 12:33 0:03 /opt/py3/bin/python3.8 /opt/py3/bin/celery worker -P threads -A ops -l INFO -c 10 -Q celery -n celery@%h
root 2766 7.4 5.1 895432 154652 ? Sl 12:33 0:03 /opt/py3/bin/python3.8 /opt/py3/bin/celery flower -A ops -l INFO --url_prefix=/core/flower --auto_refresh=False --max_tasks=1000 --tasks_columns=uuid,name,args,state,received,started,runtime,worker
root 3720 8.6 5.1 527144 154636 ? Sl 12:34 0:03 /opt/py3/bin/python3.8 /opt/py3/bin/celery beat -A ops -l INFO --scheduler django_celery_beat.schedulers:DatabaseScheduler --max-interval 60
root 2468 5.5 4.7 592568 144700 ? Sl 12:33 0:02 /opt/py3/bin/python3.8 /opt/py3/bin/gunicorn jumpserver.wsgi -b 0.0.0.0:8080 -k gthread --threads 10 -w 4 --max-requests 4096 --access-logformat %(h)s %(t)s %(L)ss "%(r)s" %(s)s %(b)s --access-logfile -
2、编写脚本,使用for和while分别实现192.168.0.0/24网段内,地址是否能够ping通,若ping通则输出"success!",若ping不通则输出"fail!"
#!/bin/bash
NETID=192.168.0.
for HOSTID in {1..254};do
{
if /bin/ping -c1 -W1 $NETID$HOSTID >/dev/null ;then
echo "$NETID$HOSTID is up."
else
echo "$NETID$HOSTID is down."
fi
} &
done
wait
[12:36:46 root@localhost ~]#chmod +x ip.sh
[12:36:50 root@localhost ~]#bash ip.sh
3、每周的工作日1:30,将/etc备份至/backup目录中,保存的文件名称格式 为“etcbak-yyyy-mm-dd-HH.tar.xz”,其中日期是前一天的时间
#!/bin/bash
[ -d /backup ] || mkdir /backup
rpm -q xz >/dev/null
[ $? -eq 0 ] || yum -y install xz >/dev/null
DATEFORMAT=`date -d yesterday "+%Y-%m-%d-%H"`
tar -cf /backup/etcbak-$DATEFORMAT.tar /etc > /dev/null && xz -z /backup/etcbak-$DATEFORMAT.tar
[12:39:36 root@localhost ~]#chmod +x backup.sh
[12:40:03 root@localhost ~]#vim /etc/crontab
1 SHELL=/bin/bash
2 PATH=/sbin:/bin:/usr/sbin:/usr/bin
3 MAILTO=root
4
5 # For details see man 4 crontabs
6
7 # Example of job definition:
8 # .---------------- minute (0 - 59)
9 # | .------------- hour (0 - 23)
10 # | | .---------- day of month (1 - 31)
11 # | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
12 # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
13 # | | | | |
14 # * * * * * user-name command to be executed
15 30 1 * * 0 root bash /data/backup.sh &>/dev/null