1、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#;
]# cp -v /etc/rc.d/rc.sysinit /tmp/
`/etc/rc.d/rc.sysinit' -> `/tmp/rc.sysinit'
]# sed 's@^[[:space:]]\+@#@g' /tmp/rc.sysinit
2、复制/boot/grub/grub.conf至/tmp目录中,删除/tmp/grub.conf文件中的行首的空白字符;
]# cp -v /boot/grub/grub.conf /tmp/
]# sed 's/^[[:space:]]\+//g' grub.conf
3、删除/tmp/rc.sysinit文件中的以#开头,且后面跟了至少一个空白字符的行行的#和空白字符
]# 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
# Set default affinity
# Load other user-defined modules
# Load modules (for backward compatibility with VARs)
# Configure kernel parameters
# Set the hostname.
# Sync waiting for storage.
# Device mapper & related initialization
# Start any MD RAID arrays that haven't been started yet
# Remount the root filesystem read-write.
# Clean up SELinux labels
# If relabeling, relabel mount points.
# Mount all other filesystems (except for NFS and /proc, which is already
# mounted). Contrary to standard usage,
...
]# sed '/^#[[:space:]]\+/d' /tmp/rc.sysinit
4、为/tmp/grub.conf文件中前三行的行首加#号;
]# sed '1,3s@^.*@#@g' /tmp/grub.conf
#
#
#
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/mapper/VolGroup-lv_root
# initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.32-431.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
initrd /initramfs-2.6.32-431.el6.x86_64.img
5、将/etc/yum.repos.d/CentOS-Media.repo文件中所有的enabled=0或gpgcheck=0的最后的0修改为1;
]# sed 's@\([enabled|gpgcheck]\)=0@\1=1@g' /etc/yum.repos.d/centos.repo
6、每4小时执行一次对/etc目录的备份,备份至/backup目录中,保存的目录名为形如etc-201504020202
]# crontab -l
0 */4 * * * /bin/cp -a /etc /backup/etc-$(date "+%Y%m%d%H%M") &>/dev/null
7、每周2,4,6备份/var/log/messages文件至/backup/messages_logs/目录中,保存的文件名形如messages-20150402
]# crontab -l
0 0 * * 2,4,6 /bin/cp -a /var/log/messages /backup/messages_logs/messages-$(date "+%Y%m%d)" &>/dev/null
8、每天每两小时取当前系统/proc/meminfo文件中的所有以S开头的信息至/stats/memory.txt文件中
]# crontab -l
0 */2 * * * grep "^S" /proc/meminfo >>/stats/memory.txt
9、工作日的工作时间内,每两小时执行一次echo “howdy”
# crontab -l
0 */2,9-18 * * 1-5 /bin/echo "hwdy"
脚本编程练习
10、创建目录/tmp/testdir-当前日期时间;
]# mkdir /tmp/testdir-$(date "+%F-%H-%M-%S")
]# ls -d /tmp/testdir*
/tmp/testdir-2016-10-16-07-03-50
11、在此目录创建100个空文件:file1-file100
]# touch file{1..100}
]# ll file* |wc -l
100
12、显示/etc/passwd文件中位于第偶数行的用户的用户名;
~]# sed -n 'n;p' /etc/passwd |awk -F: '{print $1}'
13、创建10用户user10-user19;密码同用户名;
#!/bin/bash
#
for i in {10..19};do
if useradd user$i &>/dev/null ;then
echo user$i |passwd --stdin user$i
else
echo "user$i is exists"
fi
done
14、在/tmp/创建10个空文件file10-file19;
]# touch file{10..19}
15、把file10的属主和属组改为user10,依次类推。
]# for i in {10..19};do chown user$i:user$i file$i;done
原创文章,作者:N22-白蚁,如若转载,请注明出处:http://www.178linux.com/51911
评论列表(1条)
作业写的很棒,请跟上学习进度,加油