Linux基础第六周作业
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux基础第六周作业相关的知识,希望对你有一定的参考价值。
1、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#;
cp /etc/rc.d/rc.sysinit /tmp/ sed -n‘s/^\([[:space:]]\+\)/#\1/p’/tmp/rc.sysinit
[[email protected] tmp]# sed -n ‘s/^\([[:space:]]\+\)/#\1/p‘ rc.sysinit # . /etc/sysconfig/network # HOSTNAME=localhost #mount -n -t proc /proc /proc #mount -n -t sysfs /sys /sys >/dev/null 2>&1 #vim /tmp/rc.sysinit :%s/^[[:space:]]\+/\#&/g
2、复制/boot/grub/grub.conf至/tmp目录中,删除/tmp/grub.conf文件中的行首的空白字符;
cp /boot/grub/grub.conf /tmp/ sed -n ‘s/^[[:space:]]\+//p’ /tmp/grub.conf
[[email protected] tmp]# sed -n ‘s/^[[:space:]]\+//p‘ grub.conf root (hd0,0) kernel /vmlinuz-2.6.32-642.el6.x86_64 ro root=UUID=95f5aeee-4932-4521-8a87-7134ed8ae784 rd_NO_LUKS rd_NO_LVM.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet initrd /initramfs-2.6.32-642.el6.x86_64.img
3、删除/tmp/rc.sysinit文件中的以#开头,且后面跟了至少一个空白字符的行行的#和空白字符
sed -n ‘s/^#[[::space]]\+//p’/tmp/rc.sysinit
[[email protected] tmp]# sed -n ‘/^#[[:space:]]\+/p‘ rc.sysinit # /etc/rc.d/rc.sysinit - run once at boot time # Taken in part from Miquel van Smoorenburg‘s bcheckrc. # Check SELinux status # Print a text banner. # Only read this once. # Initialize hardware
删除替换:
[[email protected] tmp]# sed -n ‘s/^#[[:space:]]\+//p‘ rc.sysinit /etc/rc.d/rc.sysinit - run once at boot time Taken in part from Miquel van Smoorenburg‘s bcheckrc. Check SELinux status Print a text banner. Only read this once. Initialize hardware
4、为/tmp/grub.conf文件中前三行的行首加#号;
sed -n‘1,3s/^/#/p’ /tmp/grub.conf
[[email protected] tmp]# sed -n ‘1,3s/^/#/p‘ grub.conf ## grub.conf generated by anaconda ## ## Note that you do not have to rerun grub after making changes to this file
5、将/etc/yum.repos.d/CentOS-Media.repo文件中所有的enabled=0或gpgcheck=0的最后的0修改为1;
[[email protected] tmp]# sed -n -e /enabled/s/0/1/p -e /gpgcheck/s/0/1/p /etc/yum.repos.d/CentOS-Media.repo enabled=1
6、每4小时执行一次对/etc目录的备份,备份至/backup目录中,保存的目录名为形如etc-201608300202
[[email protected] tmp]crontab -e 0 */4 * * * cp -r /etc/ /backup/etc-`date +%Y%m%d%H%M`
7、每周2,4,6备份/var/log/messages文件至/backup/messages_logs/目录中,保存的文件名形如messages-20160830
[[email protected] tmp]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] tmp]mkdir /stats/ [[email protected] tmp]touch /stats/memory.txt [[email protected] tmp]crontab -e 0 */2 * * * sed -n ‘/^S/p’ /proc/meminfo >> /stats/memory.txt
9、工作日的工作时间内,每两小时执行一次echo "howdy"
[[email protected] tmp]crontab -e 0 */2 * * * echo “howdy”
脚本编程练习
10、创建目录/tmp/testdir-当前日期时间;
mkdir -p /tmp/testdir-`date +%Y%m%d%H%M`
#!/bin/bash #NAME:mkdir.sh #VERSION:v0.1 mkdir -p /tmp/testdir-`date +%Y%m%d%H%M%S`
11、在此目录创建100个空文件:file1-file100
#!/bin/bash #NAME:mkdir100.sh #VERSION:v0.1 touch ./file{1..100}
#!/bin/bash #NAME:mkdir10.sh #VERSION:v0.1 for i in {1..10};do touch ./file$i done
12、显示/etc/passw d文件中位于第偶数行的用户的用户名;
[[email protected] scripts]# sed -n ‘n;p‘ /etc/passwd|cut -d: -f1 bin adm sync halt uucp games ftp dbus
[[email protected] scripts]# awk -F: ‘{if(NR%2==0)print NR,$1}‘ /etc/passwd 2 bin 4 adm 6 sync 8 halt 10 uucp 12 games 14 ftp 16 dbus
13、创建10用户user10-user19;密码同用户名;
#!/bin/bash #NAME:mkdir10.sh #VERSION:v0.1 if [ ! $UID -eq 0 ];then echo "Only root" exit 2 fi for i in {10..19};do if id user$i &> /dev/dull ;then echo "user$i exists" else useradd user$i if [ $? -eq 0 ];then echo "user$i" | passwd --stdin user$i &> /dev/dull echo "Add user$i finished" fi fi done
14、在/tmp/创建10个空文件file10-file19;
#!/bin/bash #VERSION:v0.1 touch /tmp/file{10..19}
15、把file10的属主和属组改为user10,依次类推。
#!/bin/bash #NAME:mkdir10.sh #VERSION:v0.1 for i in {10..19};do chown user$i:user$i /tmp/file$i done
七星合欢:ptting:forestlp
本文出自 “11460225” 博客,请务必保留此出处http://11470225.blog.51cto.com/11460225/1852040
以上是关于Linux基础第六周作业的主要内容,如果未能解决你的问题,请参考以下文章