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

python123第六周作业,马哥2016全新Linux+Python高端运维班第六周作业相关推荐

  1. python123第五周作业答案_马哥2016全新Linux+Python高端运维班第五周作业

    本周作业内容: 1.显示当前系统上root.fedora或user1用户的默认shell:# 没有fedora.user1用户,添加fadora,user1模拟环境 [root@localhost ~ ...

  2. python123平台作业答案第十一周_马哥2016全新Linux+Python高端运维班第十次作业

    系统的INPUT和OUTPUT默认策略为DROP,请完成以下关于iptables的题目:iptables -A INPUT -d 10.18.11.13 -p tcp --dport 22 -j AC ...

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

    一.请描述网桥.集线器.二层交换机.三层交换机.路由器的功能.使用场景与区别. 网桥(Bridge) 网桥是第2层的设备,它设计用来创建两个或多个LAN分段.其中,每一个分段都是一个独立的冲突域.网桥 ...

  4. python第七周答案_马哥2016全新Linux+Python高端运维班第七周作业

    1.创建一个10G分区,并格式为ext4文件系统: [root@localhost ~]# fdisk /dev/sdb 欢迎使用 fdisk (util-linux 2.23.2). 更改将停留在内 ...

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

    1.创建一个10G分区,并格式为ext4文件系统: # fdisk device 子命令:管理功能 p: print, 显示已有分区: n: new, 创建 d: delete, 删除 w: writ ...

  6. 鸟哥马哥共叙Linux发展

    导读 北京时间3月28日,由51CTO学院和人民邮电出版社信息技术分社联合举办的[开放·见远]"鸟哥"大陆行Linux技术沙龙在位于北京市西三环久凌大厦的51CTO学院举行. 台湾 ...

  7. Linux 运维工程师的六类好习惯

    2019独角兽企业重金招聘Python工程师标准>>> 当初学习Linux的使用,从基础到服务到集群,都是在虚拟机做的,虽然老师告诉我们跟真机没有什么差别,可是对真实环境的渴望日渐上 ...

  8. 写运维实习生第五周实习周报,包括心得体会和下周计划,多于300字

    这周我主要学习了Linux操作系统的基础知识,包括如何使用命令行.文件系统的目录结构.进程管理.用户权限等.在学习的过程中,我逐渐感受到了Linux的强大和灵活性,并且也开始能够熟练地使用命令行进行日 ...

  9. python cmdb_python自动化运维之CMDB篇-大米哥

    python自动化运维之CMDB篇 视频地址:复制这段内容后打开百度网盘手机App,操作更方便哦 链接:https://pan.baidu.com/s/1Oj_sglTi2P1CMjfMkYKwCQ  ...

最新文章

  1. Check failed: error == cudaSuccess (8 vs. 0) invalid device function
  2. python:django应用问题汇总
  3. LaneCat网猫软件
  4. Segment-段(SAP)
  5. CodeForces 1009B(思路)
  6. 信号量、使用信号量来完成读写模型(消费者生产者模型)线程池、读写锁面试题
  7. 0基础半路转行学IT还来得及吗?
  8. IOS CopyPNGFile 异常问题解决
  9. 实习成长之路:MySQL八:普通索引和唯一索引,应该怎么选择?
  10. 校园卡管理系统c语言代码,基于C++的校园一卡通管理系统
  11. 淳于髡(约前386年—前310年)
  12. 【Docker学习笔记 七】深入理解Docker网络配置及微服务部署
  13. 手机连接不上电脑的移动热点?
  14. java forward怎么用_【后端开发】java中forward是什么
  15. C++程序设计(矩形法求定积分)
  16. 第十七章 再论没有银弹
  17. 转圈加载html,web前端入门到实战:纯CSS实现加载转圈样式
  18. python支持wps_python启动办公软件进程(word、excel、ppt、以及wps的et、wps、wpp)
  19. 正态分布与泊松分布的关系
  20. 使用arduino mega2560制作一台超简易的假机械臂!

热门文章

  1. Axis2联接WCF(比较完整的版本)
  2. Ubuntu18.04安装Android Studio
  3. C++之stringstream(字符串与数字相互转换)
  4. GStreamer架构设计篇(四)
  5. Camera系统之ISP综述(一)
  6. 使用libhybris库linux调用android库
  7. shell解析xml文件
  8. LD_PRELOAD用法总结
  9. Input调用流程(好文)
  10. 非均匀采样的kalman滤波