1、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#;
 
 
    [root@localhost tmp]# cp /etc/rc.d/rc.sysinit /tmp
    [root@localhost tmp]# ls /tmp
    rc.sysinit
    [root@localhost tmp]# vim /tmp/rc.sysinit  
    :%s/^[[:space:]]/#&/
 
 
2、复制/boot/grub/grub.conf至/tmp目录中,删除/tmp/grub.conf文件中的行首的空白字符;
 
 
    [root@localhost grub]# cp /boot/grub/grub.conf /tmp/grub.conf
    [root@localhost grub]# ls
    grub.conf
    [root@localhost grub]# vim /tmp/grub.conf
    :%s/^[[:space:]]\+//g
 
 
3、删除/tmp/rc.sysinit文件中的以#开头,且后面跟了至少一个空白字符的行行的#和空白字符
 
 
    [root@localhost tmp]# vim rc.sysinit
    :%s/^#[[:space:]]\+//g
 
 
4、为/tmp/grub.conf文件中前三行的行首加#号;
 
 
    [root@localhost tmp]# vim grub.conf
    :1,3s/^/#/
 
 
5、将/etc/yum.repos.d/CentOS-Media.repo文件中所有的enabled=0或gpgcheck=0的最后的0修改为1
;
 
 
    [root@localhost ~]# vim /etc/yum.repos.d/CentOS-Media.repo 
    :%s/enabled=0/enabled=1/
    :%s/gpgcheck=0/gpgcheck=1/
 
 
6、每4小时执行一次对/etc目录的备份,备份至/backup目录中,保存的目录名为形如etc-201608300202
 
 
    [root@localhost ~]# 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
 
 
[root@localhost ~]#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文件中
 
 
    [root@localhost ~]#crontab -e
    0 */2 * * * grep "^S" /proc/meminfo >> /stats/memory.txt
     
 
9、工作日的工作时间内,每两小时执行一次echo "howdy"
 
 
    [root@localhost ~]#crontab -e
    0 */2 * * 1-5 echo "howdy
 
 
脚本编程练习
 
 
10、创建目录/tmp/testdir-当前日期时间;
 
 
    [root@localhost ~]# vim yicx
    #!/bin/bash
    #
    mkdir -p /tmp/testdir-`date +\%Y\%m\%d\%H\%M`
    [root@localhost ~]# ls -l /tmp
    总用量 0
    drwxr-xr-x. 2 root root 6 9月  12 20:26 testdir-201609122026
      
11、在此目录创建100个空文件:file1-file100
 
 
    [root@localhost ~]# vim yicx01
    [root@localhost ~]# ./yicx01
    [root@localhost ~]# 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
    [root@localhost ~]# cat yicx01
    #!/bin/bash
    #
    for i in {1..100};do
     touch file$i
    done
 
 
12、显示/etc/passw d文件中位于第偶数行的用户的用户名;
 
    [root@localhost ~]# vim yicx02
     
    #!/bin/bash
    #
    j=$(wc -l /etc/passwd | cut -d' ' -f1)
    for i in $(seq 2 2 $j)
    do
            head -n $i /etc/passwd | tail -n 1 | cut -d':' -f1
             
    [root@localhost ~]# ./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;密码同用户名;
    [root@localhost ~]# vim yicx03.sh
    #!/bin/bash
     
    for i in {10..19};do
        useradd user$i && echo "user$i" | passwd --stdin user$i
        echo "user$i created!"
    done
     
    [root@localhost ~]# 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;
 
 
    [root@localhost ~]# bash yicx04.sh
    file10 created!
    file11 created!
    file12 created!
    file13 created!
    file14 created!
    file15 created!
    file16 created!
    file17 created!
    file18 created!
    file19 created!
    [root@localhost ~]# cat yicx04.sh 
    #!/bin/bash
    #
    for i in {10..19};do
     touch file$i
        echo "file$i created!"
    done
 
  
15、把file10的属主和属组改为user10,依次类推。
 
 
    [root@localhost ~]# vim yicx05.sh
    [root@localhost ~]# bash yicx05.sh 
    [root@localhost ~]# 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 桌面
    [root@localhost ~]# cat yicx05.sh 
    #!/bin/bash
    #
    for i in {10..19};do
    chown user$i:user$i file$i
    done

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

  1. Python Linux系统管理与自动化运维

    Python Linux系统管理与自动化运维 前言 第1章Python语言与Linux系统管理1 1.1Python语言有多流行1 1.2Python语言为什么流行3 1.3Python语言有什么缺点 ...

  2. Linux实战型企业运维工程师试题

    1.如何通过Linux配置一个局域网或者IDC机房上网网关,请给出步骤及命令?答:上网网关配置(1)开启内核转发:sed -i 's#net.ipv4.ip_forward = 0#net.ipv4. ...

  3. Linux实战型企业运维工程师试题测评

    Linux实战型企业运维工程师试题答案 作者:尹正杰      最近在网上看到了一套有意思的面试题,我们一起来看一下这些题怎么破吧,哈哈~我先放在这里,有时间了一起来看看.多学点东西终究是没有坏处的! ...

  4. Linux内核高端内存 转

        Linux内核地址映射模型x86 CPU采用了段页式地址映射模型.进程代码中的地址为逻辑地址,经过段页式地址映射后,才真正访问物理内存. 段页式机制如下图.   Linux内核地址空间划分 通 ...

  5. Linux内核高端内存

    Linux内核地址映射模型 x86 CPU采用了段页式地址映射模型.进程代码中的地址为逻辑地址,经过段页式地址映射后,才真正访问物理内存. 段页式机制如下图. Linux内核地址空间划分 通常32位L ...

  6. 2017-2018-1 《Linux内核原理与设计》第十二周作业

    <linux内核原理与设计>第十二周作业 Sql注入基础原理介绍 分组: 和20179215袁琳完成实验 一.实验说明   SQL注入攻击通过构建特殊的输入作为参数传入Web应用程序,而这 ...

  7. 2019-2020-1 20199329《Linux内核原理与分析》第六周作业

    <Linux内核原理与分析>第六周作业 一.本周内容概述: 学习系统调用的相关理论知识,并使用库函数API和C代码中嵌入汇编代码两种方式使用getpid()系统调用 学习系统调用syste ...

  8. 2018-2019-1 20189221 《Linux内核原理与分析》第六周作业

    2018-2019-1 20189221 <Linux内核原理与分析>第六周作业 实验五 实验过程 将Fork函数移植到Linux的MenuOS fork()函数通过系统调用创建一个与原来 ...

  9. 2019-2020-1 20199329《Linux内核原理与分析》第十二周作业

    <Linux内核原理与分析>第十二周作业 一.本周内容概述: 通过编程理解 Set-UID 的运行机制与安全问题 完成实验楼上的<SET-UID程序漏洞实验> 二.本周学习内容 ...

随机推荐

  1. JMeter学习笔记(九) 参数化3--User Defined Variables

    3.User Defined Variables 1)添加用户定义的变量 2)添加变量 3)添加HTTP请求,引用变量,格式:${} 4)执行HTTP请求,察看结果树 5)用户定义的变量,优缺点: * ...

  2. 1098 Insertion or Heap Sort (25 分)(堆)

    这里的第二序列相当于是排序还没拍好的序列 对于第二个样例的第二个序列其实已经是大顶堆了 然后才进行的堆排序 知道这个就好做了 #include<bits/stdc++.h> using n ...

  3. MySql数据库插入或更新报错:Cannot add or update a child row: a foreign key constraint fails

    具体报错信息: Cannot add or update a child row: a foreign key constraint fails (`xxx`.`AAA`, CONSTRAINT `t ...

  4. (转载)MYSQL千万级数据量的优化方法积累

    转载自:http://blog.sina.com.cn/s/blog_85ead02a0101csci.html MYSQL千万级数据量的优化方法积累 1.分库分表 很明显,一个主表(也就是很重要的表 ...

  5. RadioGroup和GroupBox有什么区别?

    我在RadioGroup中放RadioButton和GroupBox中一样,搞不明白. radiogroup有个item属性都是radio控件,不需要拖控件上去.groupbox需要自己拖控件 分组的 ...

  6. [USACO07DEC]美食的食草动物Gourmet Grazers

    ---题面--- 题解: 首先观察题面,直觉上对于一头奶牛,肯定要给它配pi和qi符合条件的草中两者尽量低的草,以节省下好草给高要求的牛. 实际上这是对的,但观察到两者尽量低这个条件并不明确,无法用于 ...

  7. BZOJ1093 [ZJOI2007]最大半连通子图 【tarjan缩点 + DAG最长路计数】

    题目 一个有向图G=(V,E)称为半连通的(Semi-Connected),如果满足:?u,v∈V,满足u→v或v→u,即对于图中任意 两点u,v,存在一条u到v的有向路径或者从v到u的有向路径.若G ...

  8. 洛谷 P2444 [POI2000]病毒 解题报告

    P2444 [POI2000]病毒 题目描述 二进制病毒审查委员会最近发现了如下的规律:某些确定的二进制串是病毒的代码.如果某段代码中不存在任何一段病毒代码,那么我们就称这段代码是安全的.现在委员会已 ...

  9. [学习笔记]动态dp

    其实就过了模板. 感觉就是带修改的dp [模板]动态dp 给定一棵n个点的树,点带点权. 有m次操作,每次操作给定x,y表示修改点x的权值为y. 你需要在每次操作之后求出这棵树的最大权独立集的权值大小 ...

  10. springMvc--请求的跳转和传值

    springMvc--请求的跳转和传值 目录 forword跳转页面的三种方式 1.使用serlvet 2.使用Model对象 3.使用ModelAndView redirect跳转到页面 使用ser ...