Linux+Python高端运维班第六周作业

1、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#;

    [[email protected] tmp]# cp /etc/rc.d/rc.sysinit /tmp

    [[email protected] tmp]# ls /tmp

    rc.sysinit

    [[email protected] tmp]# vim /tmp/rc.sysinit  

    :%s/^[[:space:]]/#&/

2、复制/boot/grub/grub.conf至/tmp目录中,删除/tmp/grub.conf文件中的行首的空白字符;

    [[email protected] grub]# cp /boot/grub/grub.conf /tmp/grub.conf

    [[email protected] grub]# ls

    grub.conf

    [[email protected] grub]# vim /tmp/grub.conf

    :%s/^[[:space:]]\+//g

3、删除/tmp/rc.sysinit文件中的以#开头,且后面跟了至少一个空白字符的行行的#和空白字符

    [[email protected] tmp]# vim rc.sysinit

    :%s/^#[[:space:]]\+//g

4、为/tmp/grub.conf文件中前三行的行首加#号;

    [[email protected] tmp]# vim grub.conf

    :1,3s/^/#/

5、将/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=0/enabled=1/

    :%s/gpgcheck=0/gpgcheck=1/

6、每4小时执行一次对/etc目录的备份,备份至/backup目录中,保存的目录名为形如etc-201608300202

    [[email protected] ~]# crontab -e

    # 0 */4 * * * /bin/cp -a /etc/ /backup/etc-$(date +%Y%m%d%H%M)

7、每周2,4,6备份/var/log/messages文件至/backup/messages_logs/目录中,保存的文件名形如messages-20160830

[[email protected] ~]#crontab -e

0 0 * * 2,4,6 cp /var/log/messages /backup/messages_logs/messages-`date +\%Y\%m\%d

8、每天每两小时取当前系统/proc/meminfo文件中的所有以S开头的信息至/stats/memory.txt文件中

    [[email protected] ~]#crontab -e

    0 */2 * * * grep "^S" /proc/meminfo >> /stats/memory.txt

    

9、工作日的工作时间内,每两小时执行一次echo "howdy"

    [[email protected] ~]#crontab -e

    0 */2 * * 1-5 echo "howdy

脚本编程练习

10、创建目录/tmp/testdir-当前日期时间;

    [[email protected] ~]# vim yicx

    #!/bin/bash

    #

    mkdir -p /tmp/testdir-`date +\%Y\%m\%d\%H\%M`

    [[email protected] ~]# ls -l /tmp

    总用量 0

    drwxr-xr-x. 2 root root 6 9月  12 20:26 testdir-201609122026

     

11、在此目录创建100个空文件:file1-file100

    [[email protected] ~]# vim yicx01

    [[email protected] ~]# ./yicx01

    [[email protected] ~]# ls

    file1    file2   file30  file41  file52  file63  file74  file85  file96

    file10   file20  file31  file42  file53  file64  file75  file86  file97

    file100  file21  file32  file43  file54  file65  file76  file87  file98

    file11   file22  file33  file44  file55  file66  file77  file88  file99

    file12   file23  file34  file45  file56  file67  file78  file89  yicx

    file13   file24  file35  file46  file57  file68  file79  file9   yicx01

    file14   file25  file36  file47  file58  file69  file8   file90

    file15   file26  file37  file48  file59  file7   file80  file91

    file16   file27  file38  file49  file6   file70  file81  file92

    file17   file28  file39  file5   file60  file71  file82  file93

    file18   file29  file4   file50  file61  file72  file83  file94

    file19   file3   file40  file51  file62  file73  file84  file95

    [[email protected] ~]# cat yicx01

    #!/bin/bash

    #

    for in {1..100};do

     touch file$i

    done

12、显示/etc/passw d文件中位于第偶数行的用户的用户名;

    [[email protected] ~]# vim yicx02

    

    #!/bin/bash

    #

    j=$(wc -l /etc/passwd cut -d‘ ‘ -f1)

    for in $(seq 2 2 $j)

    do

            head -n $i /etc/passwd tail -n 1 | cut -d‘:‘ -f1

            

    [[email protected] ~]# ./yicx02

    bin

    adm

    sync

    halt

    operator

    ftp

    systemd-bus-proxy

    dbus

    abrt

    tss

    usbmuxd

    saslauth

    rpc

    chrony

    qemu

    rpcuser

    avahi-autoipd

    sssd

    gdm

    sshd

    postfix

    yicx

13、创建10用户user10-user19;密码同用户名;

    [[email protected] ~]# vim yicx03.sh

    #!/bin/bash

    

    for in {10..19};do

        useradd user$i && echo "user$i" passwd --stdin user$i

        echo "user$i created!"

    done

    

    [[email protected] ~]# bash yicx03.sh 

    更改用户 user10 的密码 。

    passwd:所有的身份验证令牌已经成功更新。

    user10 created!

    更改用户 user11 的密码 。

    passwd:所有的身份验证令牌已经成功更新。

    user11 created!

    更改用户 user12 的密码 。

    passwd:所有的身份验证令牌已经成功更新。

    user12 created!

    更改用户 user13 的密码 。

    passwd:所有的身份验证令牌已经成功更新。

    user13 created!

    更改用户 user14 的密码 。

    passwd:所有的身份验证令牌已经成功更新。

    user14 created!

    更改用户 user15 的密码 。

    passwd:所有的身份验证令牌已经成功更新。

    user15 created!

    更改用户 user16 的密码 。

    passwd:所有的身份验证令牌已经成功更新。

    user16 created!

    更改用户 user17 的密码 。

    passwd:所有的身份验证令牌已经成功更新。

    user17 created!

    更改用户 user18 的密码 。

    passwd:所有的身份验证令牌已经成功更新。

    user18 created!

    更改用户 user19 的密码 。

    passwd:所有的身份验证令牌已经成功更新。

    

14、在/tmp/创建10个空文件file10-file19;

    [[email protected] ~]# bash yicx04.sh

    file10 created!

    file11 created!

    file12 created!

    file13 created!

    file14 created!

    file15 created!

    file16 created!

    file17 created!

    file18 created!

    file19 created!

    [[email protected] ~]# cat yicx04.sh 

    #!/bin/bash

    #

    for in {10..19};do

     touch file$i

        echo "file$i created!"

    done

 

15、把file10的属主和属组改为user10,依次类推。

    [[email protected] ~]# vim yicx05.sh

    [[email protected] ~]# bash yicx05.sh 

    [[email protected] ~]# ll 

    总用量 20

    -rw-------. 1 root   root   1287 9月   7 05:10 anaconda-ks.cfg

    -rw-r--r--. 1 user10 user10    0 9月  12 21:23 file10

    -rw-r--r--. 1 user11 user11    0 9月  12 21:23 file11

    -rw-r--r--. 1 user12 user12    0 9月  12 21:23 file12

    -rw-r--r--. 1 user13 user13    0 9月  12 21:23 file13

    -rw-r--r--. 1 user14 user14    0 9月  12 21:23 file14

    -rw-r--r--. 1 user15 user15    0 9月  12 21:23 file15

    -rw-r--r--. 1 user16 user16    0 9月  12 21:23 file16

    -rw-r--r--. 1 user17 user17    0 9月  12 21:23 file17

    -rw-r--r--. 1 user18 user18    0 9月  12 21:23 file18

    -rw-r--r--. 1 user19 user19    0 9月  12 21:23 file19

    -rw-------. 1 root   root   1335 9月   6 21:20 initial-setup-ks.cfg

    -rw-r--r--. 1 root   root    132 9月  12 21:20 yicx03.sh

    -rw-r--r--. 1 root   root     82 9月  12 21:23 yicx04.sh

    -rw-r--r--. 1 root   root     72 9月  12 21:28 yicx05.sh

    drwxr-xr-x. 2 root   root      6 9月  12 21:00 公共

    drwxr-xr-x. 2 root   root      6 9月  12 21:00 模板

    drwxr-xr-x. 2 root   root      6 9月  12 21:00 视频

    drwxr-xr-x. 2 root   root      6 9月  12 21:00 图片

    drwxr-xr-x. 2 root   root      6 9月  12 21:00 文档

    drwxr-xr-x. 2 root   root      6 9月  12 21:00 下载

    drwxr-xr-x. 2 root   root      6 9月  12 21:00 音乐

    drwxr-xr-x. 2 root   root      6 9月  12 21:00 桌面

    [[email protected] ~]# cat yicx05.sh 

    #!/bin/bash

    #

    for in {10..19};do

    chown user$i:user$i file$i

    done

时间: 2024-08-04 03:37:00

Linux+Python高端运维班第六周作业的相关文章

马哥2016全新Linux+Python高端运维班第六周作业

1.复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#: 答:可使用vim的查找替换功能完成: 命令如下: [[email protected] ~]# cp /etc/rc.d/rc.sysinit /tmp       ##复制文件 [[email protected] ~]# vim /tmp/rc.sysinit            ##vim编辑该文件 命令结果如下(下图红框为与上图对比效果):

马哥2016全新Linux+Python高端运维班第三周作业作答

                    马哥2016全新Linux+Python高端运维班第三周作业                                           1.列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可.     [[email protected] ~]# who | awk '{print $1 $NF}'| uniq -d     [[email protected] ~]# who     yicx     :0  

马哥2016全新Linux+Python高端运维班第八周作业

1.请描述网桥.集线器.二层交换机.三层交换机.路由器的功能.使用场景与区别. 答: 网桥:双端口的二层设备,可以隔离冲突域,一般用于划分LAN,或者链接LAN. 集线器:物理层设备,多端口,无法隔离冲突域,用于连接主机. 二层交换机:数据链路层设备,多端口,与网桥相比,交换机可学习MAC地址,根据MAC地址转发数据,可隔离冲突域,用于在路由设备与主机之间架设,接入层与汇聚层皆可使用. 三层交换机:相当于是带路由功能的二层交换机,工作在网络层,有更高的带宽,可做核心层使用,用于大中型网络的路由交

[作业] 马哥2016全新Linux+Python高端运维班第八周作业

1.请描述网桥.集线器.二层交换机.三层交换机.路由器的功能.使用场景与区别. 网桥:比较古老的方式二层交换设备,网桥的两个端口分别有一条独立的交换信道,不是共享一条背板总线,可隔离冲突域.类似中继器. 集线器: 二层交换设备,多口的网桥 二层交换机: 二层交换设备,可以识别数据包中的MAC地址信息,根据MAC地址进行转发,并将这些MAC地址与对应的端口记录在自己内部的一个地址表中 三层交换机: 工作在二层和三层,具有路由功能的交换机.三层交换机的最重要目的是加快大型局域网内部的数据交换,所具有

马哥2016全新Linux+Python高端运维班第三周作业

本周作业内容: 1.列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可. # who | cut -d' ' -f1 | sort -u 2.取出最后登录到当前系统的用户的相关信息. # id $(who | sort -t' ' -k3,4 | tail -1 | cut -d' ' -f1) 3.取出当前系统上被用户当作其默认shell的最多的那个shell. # cut -d: -f7 /etc/passwd | sort | uniq -c | sort

马哥2016全新Linux+Python高端运维班第七周作业

1.创建一个10G分区,并格式为ext4文件系统: (1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl: (2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳: 2.创建一个大小为1G的swap分区,并创建好文件系统,并启用之: 3.写一个脚本 (1).获取并列出当前系统上的所有磁盘设备: (2).显示每个磁盘设备上每个分区相关的空间使用信息: 4.总结RAID的各个级别及其组合方式和性能的不同

马哥2016全新Linux+Python高端运维班第五周作业

1.显示当前系统上root.fedora或user1用户的默认shell: 答:需要找到3个字符串,需要用到"或"命令,所以使用egrep.找到后cut再次筛选出我们需要显示的用户默认的shell. 2.找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello(): 答: 3.使用echo命令输出一个绝对路径,使用grep取出其基名: 答:首先我们要了解什么是路径的基名和路径名: 基名:可以理解为路径名最右边的名称: 路径名:除基名以外

Linux+Python高端运维班第四次作业

1.创建一个10G分区,并格式为ext4文件系统: [[email protected] ~]# fdisk /dev/sdb   //管理分区sdb 命令(输入 m 获取帮助):n    //输入命令n创建一个新分区 Select (default p): p        //设置分区类型为主分区 分区号 (1-4,默认 1):1        //设置分区号 起始 扇区 (2048-41943039,默认为 2048):    //设置起始扇区,因为这里是sdb上第一个分区所以不输入任何信

Linux+Python高端运维班第十一次作业

1.源码编译安装LNMP架构环境: (1)安装编辑工具和环境 yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel cur