Linux+Python高端运维班第三次作业
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux+Python高端运维班第三次作业相关的知识,希望对你有一定的参考价值。
1、找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello();
[[email protected] ~]# grep -E "[[:alpha:]]+\(\)+" /etc/rc.d/init.d/functions checkpid() { __pids_var_run() { __pids_pidof() { daemon() { killproc() { pidfileofproc() { pidofproc() { status() { echo_success() { echo_failure() { echo_passed() { echo_warning() { update_boot_stage() { success() { failure() { passed() { warning() { action() { strstr() { is_ignored_file() { is_true() { is_false() { apply_sysctl() {
2、使用echo命令输出一个绝对路径,使用grep取出其基名;
[[email protected] ~]# echo "/bin/bash/" | grep -E -o "[^/]+/?$" | cut -d/ -f1 bash
扩展:取出其路径名
[[email protected] ~]# echo "/bin/bash/d/" | grep -E -o "^/.*[^/]" | grep -E -o "^/.*/" /bin/bash/
3、找出ifconfig命令结果中的1-255之间数字;
[[email protected] ~]# ifconfig | grep -E -o "[[:digit:]]{1,}" | grep -E -w "(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])" 192 168 223 128 255 255 255 192 168 223 255 6 80 20 29 3 6 64 20 29 3 6 7 19 8 73 127 1 255 6 1 128 10 26 2 26 2 192 168 122 1 255 255 255 192 168 122 255 52 54 70 9 5
[[email protected] ~]# ifconfig | grep -E -w "(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])" inet 192.168.223.128 netmask 255.255.255.0 broadcast 192.168.223.255 inet6 fe80::20c:29ff:fe3d:6dea prefixlen 64 scopeid 0x20<link> ether 00:0c:29:3d:6d:ea txqueuelen 1000 (Ethernet) RX packets 501011 bytes 692867068 (660.7 MiB) TX packets 157560 bytes 20813669 (19.8 MiB) lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> RX packets 314 bytes 26870 (26.2 KiB) TX packets 314 bytes 26870 (26.2 KiB) inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52:54:00:70:c9:d5 txqueuelen 0 (Ethernet)
4、查找当前系统上没有属主或属组的文件;
[[email protected] ~]# find / -nouser -nogroup find: ‘/proc/38302/task/38302/fd/6’: No such file or directory find: ‘/proc/38302/task/38302/fdinfo/6’: No such file or directory find: ‘/proc/38302/fd/6’: No such file or directory find: ‘/proc/38302/fdinfo/6’: No such file or directory
进一步:查找当前系统上没有属主或属组,且最近3天内曾被访问过的文件或目录;
[[email protected] ~]# find / -nouser -nogroup -atime -3 find: ‘/proc/38312/task/38312/fd/6’: No such file or directory find: ‘/proc/38312/task/38312/fdinfo/6’: No such file or directory find: ‘/proc/38312/fd/6’: No such file or directory find: ‘/proc/38312/fdinfo/6’: No such file or directory
5、查找/etc目录下大于1M,且类型为普通文件的所有文件;
[[email protected] ~]# find /etc -size +1M -type f -ls 69639801 3772 -rw-r--r-- 1 root root 3858924 Nov 20 2015 /etc/selinux/targeted/policy/policy.29 135034268 6852 -r--r--r-- 1 root root 7014922 Dec 23 00:49 /etc/udev/hwdb.bin 68629841 1336 -rw-r--r-- 1 root root 1367395 Mar 5 2015 /etc/brltty/zh-tw.ctb
6、查找/etc/init.d/目录下,所有用户都有执行权限,且其它用户有写权限的文件;
[[email protected] ~]# find /etc/init.d/ -perm -113 -type f
7、查找/etc目录下最近一周内其内容被修改过,且不属于root或hadoop的文件;
[[email protected] ~]# find /etc -mtime -7 -not -user root -not -user hadoop -ls
8、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#;
[[email protected]~]# cp /etc/rc.d/rc.sysinit /tmp/ [[email protected]~]# vim /tmp/rc.sysinit
在末行模式中输入:
%s/^[[:space:]]\+/#&/g
9、删除/tmp/rc.sysinit文件中的以#开头,且后面跟了至少一个空白字符的行行的#和空白字符
[[email protected]~]# vim /tmp/rc.sysinit
在末行模式中输入:
%s/^[#][[:space:]]\+//g
10、将/etc/yum.repos.d/CentOS-Media.repo文件中所有的enabled=0或gpgcheck=0的最后的0修改为1;
[[email protected]~]# vim etc/yum.repos.d/CentOS-Media.repo
在末行模式中输入:
%s#\(enabled=\)[[:digit:]]#\11#g
%s#\(gpgcheck=\)[[:digit:]]#\11#g
11、每周2,4,6备份/var/log/messages文件至/backup/messages_logs/目录中,保存的文件名形如messages-20161202
[[email protected] ~]# crontab -e 0 0 * * 2,4,6 /bin/cp -a /var/log/messages /backup/messages_logs/messages-$(date +\%Y\%m\%d)
12、每天每两小时取当前系统/proc/meminfo文件中的所有以S开头的信息至/stats/memory.txt文件中
[[email protected] ~]# crontab -e 00 */2 * * * cat /proc/meminfo |grep "^S" >> /stats/memory.txt
13、写一个脚本创建10用户user10-user19;密码同用户名;
#!/bin/bash# for i in {10..19};do if id user$i ;then echo "user$i exists." else useradd user$i echo "user$i" | passwd --stdin user$i fi done
本文出自 “学海无涯” 博客,谢绝转载!
以上是关于Linux+Python高端运维班第三次作业的主要内容,如果未能解决你的问题,请参考以下文章