马哥教育网络班21期+第六周博客作业

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

# cp -a /etc/rc.d/rc.sysinit /tmp/
# ls /tmp/ | grep rc.sysinit
rc.sysinit
# vim /tmp/rc.sysinit
%s@^[[:space:]]\{1,\}@#&@g

执行结果片段:

[ "$PROMPT" != no ] && plymouth --ignore-keystroke=Ii
if strstr "$cmdline" confirm ; then
#       touch /var/run/confirm
fi
# Let rhgb know that we're leaving rc.sysinit
if [ -x /bin/plymouth ]; then
#    /bin/plymouth --sysinit
fi
385 次替换,共 385 行

总结:

a、@替换前@替换后@参数

b、^[[:space:]],匹配以空格开头的行

c、{1,}表示匹配至少一次之前的RE字符

d、&表示匹配之前的内容

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

[root@C67-X64-A0 ~]# cp -a /boot/grub/grub.conf /tmp/
[root@C67-X64-A0 ~]# cat -n /tmp/grub.conf 
     1 # grub.conf generated by anaconda
     2 #
     3 # Note that you do not have to rerun grub after making changes to this file
     4 # NOTICE:  You have a /boot partition.  This means that
     5 #          all kernel and initrd paths are relative to /boot/, eg.
     6 #          root (hd0,0)
     7 #          kernel /vmlinuz-version ro root=/dev/sda5
     8 #          initrd /initrd-[generic-]version.img
     9 #boot=/dev/sda
    10 default=0
    11 timeout=5
    12 splashimage=(hd0,0)/grub/splash.xpm.gz
    13 hiddenmenu
    14 title CentOS 6 (2.6.32-573.el6.x86_64)
    15 root (hd0,0)
    16 kernel /tboot.gz logging=vga,serial,memory
    17 module /vmlinuz-2.6.32-573.el6.x86_64 ro root=UUID=922eb46f-7e6e-4670-8bf1-6f9f1b05a053 intel_iommu=on amd_iommu=on rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=128M.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
    18 module /initramfs-2.6.32-573.el6.x86_64.img
[root@C67-X64-A0 ~]# vim /tmp/grub.conf
%s#^[[:space:]]##g
[root@C67-X64-A0 ~]# cat -n /tmp/grub.conf 
     1 # grub.conf generated by anaconda
     2 #
     3 # Note that you do not have to rerun grub after making changes to this file
     4 # NOTICE:  You have a /boot partition.  This means that
     5 #          all kernel and initrd paths are relative to /boot/, eg.
     6 #          root (hd0,0)
     7 #          kernel /vmlinuz-version ro root=/dev/sda5
     8 #          initrd /initrd-[generic-]version.img
     9 #boot=/dev/sda
    10 default=0
    11 timeout=5
    12 splashimage=(hd0,0)/grub/splash.xpm.gz
    13 hiddenmenu
    14 title CentOS 6 (2.6.32-573.el6.x86_64)
    15 root (hd0,0)
    16 kernel /tboot.gz logging=vga,serial,memory
    17 module /vmlinuz-2.6.32-573.el6.x86_64 ro root=UUID=922eb46f-7e6e-4670-8bf1-6f9f1b05a053 intel_iommu=on amd_iommu=on rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=128M.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
    18 module /initramfs-2.6.32-573.el6.x86_64.img

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

# vim /tmp/rc.sysinit 
:%s@^#[[:space:]]\+@@g
执行结果如下:
Now that we have all of our basic modules loaded and the kernel going,
let's dump the syslog ring somewhere so we can find it later
[ -f /var/log/dmesg ] && mv -f /var/log/dmesg /var/log/dmesg.old
dmesg -s 131072 > /var/log/dmesg
create the crash indicator flag to warn on crashes, offer fsck with timeout
touch /.autofsck &> /dev/null
[ "$PROMPT" != no ] && plymouth --ignore-keystroke=Ii
if strstr "$cmdline" confirm ; then
        touch /var/run/confirm
fi
Let rhgb know that we're leaving rc.sysinit
if [ -x /bin/plymouth ]; then
    /bin/plymouth --sysinit
fi

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

# vim /tmp/grub.conf
末行模式下:
1,3s@^.*@#&

5、将/etc/yum.repos.d/CentOS-Media.repo文件中所有的enabled=0或gpgcheck=0的最后的0修改为1;

%s@\(enabled\|gpgcheck\)=0@\1=1@g

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

# mkdir -p /backup
# crontab -l
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-20150402

# mkdir -p /backup/messages_logs
# cp -a /var/log/messages /backup/messages_logs/messages-`date +%Y%m%d`
# ls -l /backup/messages_logs/messages-201608
messages-201608    messages-20160809  
说明: messages-20160809 满足此条件
[root@C67-X64-A0 cron]# crontab -e
0 */4 * * * /bin/cp -a /etc/ /backup/etc-$(date +%Y%m%d%H%M) >/dev/null 2>&1
0 0 * * 2,4,6 /bin/cp -a /var/log/messages /backup/messages_logs/messages-`date +%Y%m%d`>/dev/null 2>&1
[root@C67-X64-A0 cron]# cat /var/spool/cron/root 
0 */4 * * * /bin/cp -a /etc/ /backup/etc-$(date +%Y%m%d%H%M) >/dev/null 2>&1
0 0 * * 2,4,6 /bin/cp -a /var/log/messages /backup/messages_logs/messages-`date +%Y%m%d`>/dev/null 2>&1

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

[root@C67-X64-A0 cron]# mkdir -p /stats
[root@C67-X64-A0 cron]# touch /stats/memory.txt
[root@C67-X64-A0 cron]# grep "^S" /proc/meminfo >>/stats/memory.txt
[root@C67-X64-A0 cron]# cat /stats/memory.txt 
SwapCached:            0 kB
SwapTotal:       4194300 kB
SwapFree:        4194300 kB
Shmem:              1340 kB
Slab:             134788 kB
SReclaimable:      91524 kB
SUnreclaim:        43264 kB
# crontab -e
0 */2 * * * grep "^S" /proc/meminfo >>/stats/memory.txt

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

0 9-18/2 * * 1-5 /bin/echo "howdy"

脚本编程练习(这里没考虑文件、用户或目录本来就存在的情况)

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

# mkdir -p /tmp/testdir-$(date +%F)

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

#!/bin/bash
#created by molewan
for i in `seq 1 100`
do
touch file$i
done

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

# sed -n 'n;p' /etc/passwd |awk -F":" '{print $1}'

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

#!/bin/bash
#created by molewan
for i in $(seq 10 19)
        do
                useradd user$i
                echo user$i | passwd --stdin user$i
        done

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

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

#!/bin/bash
#created by molewan
for i in $(seq 10 19)
        do
                touch file$i
chown user$i:user$i /tmp/file$i
        done

原创文章,作者:Net21-冰冻vs西瓜,如若转载,请注明出处:http://www.178linux.com/31947

(0)
上一篇 2016-08-15 12:10
下一篇 2016-08-15 12:10

相关推荐

  • ip子网划分

    ip子网划分 人们为了通信方便,给每台计算机分配了一个类似我们电话号码一样的标识地址。IP就好比一个人的指纹一样,在INTERNET中是独一无二的(公网中)。我们可以通过ip查询到使用该ip的主机。 现在的IP分为ipv4和ipv6。前者是32位二进制组成,为了防止IP不够用由此研发出后者ipv6,ipv6是由128位二进制组成。ipv6中包含ip的数量相当…

    Linux干货 2017-07-01
  • N26-第九周作业-邢岩

    马哥门徒-N26-邢岩 相信自己、勤奋努力、不断总结!shell脚本练习需要重复、重复、再重复!那么,我就继续来写、写、写。 1、写一个脚本,判断当前系统上所有用户的shell是否为可登录shell(即用户的shell不是/sbin/nologin);分别这两类用户的个数;通过字符串比较来实现; #******************************…

    Linux干货 2017-04-03
  • 马哥教育网络班22期+第5周课程练习

    1、显示当前系统上root、fedora或user1用户的默认shell; [root@rhel677850 ~]# grep "^\(root\|fedora\|user1\)" /etc/passwd|awk -F: '{print $1,$7}&#039…

    Linux干货 2016-09-26
  • Linux下的LVM管理命令

    一. 何为LVM?     Logical Volume Manager的缩写,它可以把多个分区、硬盘甚至RAID组合成一个存储设备来使用,并可以扩展或缩减空间。LVM有三层组成组成:底层的PV,中间的VG,上层的LV,如图所示         &n…

    Linux干货 2015-12-06
  • N26-第四周-孙逸

    1、  复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 cp –r /etc/skel /home/tuser1 chmod –R 700 /home/tuser1 2、  编辑/etc/group文件,添加组hadoop。 group文件的内容格式: &…

    2017-03-10
  • 单向加密原理

      单向加密算法对数据进行加密的过程分为两个步骤:   一、添加特征码           上图中说明了为数据添加特征码的步骤:       1、使用单向算法计算出特征码       2、使用私钥来加密特征码   &nb…

    Linux干货 2016-02-24

评论列表(1条)

  • 马哥教育
    马哥教育 2016-08-17 15:05

    写的很好,排版也很棒,加油