"Linux Basics" week sixth job

Source: Internet
Author: User

1. copy The/etc/rc.d/rc.sysinit file to the/tmp directory and add # to the beginning of the line with at least one whitespace character in the/tmp/rc.sysinit file;

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, copy/boot/grub/grub.conf to/tmp directory, delete the blank character of the beginning of the/tmp/grub.conf file;

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 quietinitrd/ Initramfs-2.6.32-642.el6.x86_64.img


3. remove the # and white space characters from the/tmp/rc.sysinit file that begin with # and followed by at least one white-space character

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 PA RT from Miquel van Smoorenburg ' s bcheckrc.# Check SELinux status# Print A text banner.# only read this once.# Initialize h Ardware

To delete a replacement:

[[email protected] tmp]# sed-n ' s/^#[[:space:]]\+//p ' rc.sysinit/etc/rc.d/rc.sysinit-run once at boot Timetaken in par T from Miquel van Smoorenburg ' s BCHECKRC. Check SELinux statusprint a text banner. Only read this once. Initialize Hardware


4. Add # to the beginning of the first three lines in the/tmp/grub.conf file;

Sed-n ' 1,3s/^/#/p '/tmp/grub.conf

[[email protected] tmp]# sed-n ' 1,3s/^/#/p ' grub.conf # # grub.conf generated by anaconda#### O Rerun grub after making changes to the This file


5. Change the last 0 of all enabled=0 or gpgcheck=0 in the/etc/yum.repos.d/centos-media.repo file to 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, every 4 hours to perform a backup of the/etc directory, back up to the/backup directory, save the directory named Shape etc-201608300202

[[email protected] TMP]CRONTAB-E0 */4 * * * cp-r/etc//backup/etc-' Date +%y%m%d%h%m '


7, weekly 2,4,6 backup/var/log/messages file to/backup/messages_logs/directory, save the file name like messages-20160830

[[email protected] TMP]CRONTAB-E0 0 * * */2,4,6 cp/var/log/messages/backup/messages_logs/messages-' date +%y%m%d '


8, every two hours every day to take the current system /proc/meminfo file in the beginning of all the information in the S./stats/memory.txt file

[[Email protected] tmp]mkdir/stats/[[email protected] tmp]touch/stats/memory.txt[[email protected] tmp]crontab-e0 */2 * * * * sed-n '/^s/p '/proc/meminfo >>/stats/memory.txt


9, working days of work time, every two hours to perform the echo "Howdy"

[[email protected] TMP]CRONTAB-E0 */2 * * * echo "howdy"


Script Programming Exercises

10, Create the directory /tmp/testdir-the current date and time;

Mkdir-p/tmp/testdir-' Date +%y%m%d%h%m '
#!/bin/bash#name:mkdir.sh#version:v0.1mkdir-p/tmp/testdir-' Date +%y%m%d%h%m%s '


11. Create 100 empty files in this directory : file1-file100

#!/bin/bash#name:mkdir100.sh#version:v0.1touch./file{1..100}


#!/bin/bash#name:mkdir10.sh#version:v0.1for i in {1..10};d o touch./file$idone


12. Display the user name of the user who is located in the/ETC/PASSW D file in the first even row;

[Email protected] scripts]# sed-n ' n;p '/etc/passwd|cut-d:-f1binadmsynchaltuucpgamesftpdbus


[Email protected] scripts]# awk-f: ' {if (nr%2==0) print nr,$1} '/etc/passwd2 bin4 adm6 sync8 halt10 uucp12 games14 ftp16 D Bus


create 10 user user10-user19; password with user name;

#!/bin/bash#name:mkdir10.sh#version:v0.1if [ !  $UID  -eq 0 ];then     echo  "Only root"     exit 2fifor i in {10..19};d O     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 &nBsp;  fidone 


14, create 10 empty files File10-file19 in /tmp/;

#!/bin/bash#version:v0.1touch/tmp/file{10..19}


15. Change the File10 and the genus to user10, and so on.

#!/bin/bash#name:mkdir10.sh#version:v0.1for i in {10..19};d o chown user$i:user$i/tmp/file$idone


Seven Stars Acacia: PTTING:FORESTLP

This article is from the "11460225" blog, please be sure to keep this source http://11470225.blog.51cto.com/11460225/1852040

"Linux Basics" week sixth job

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.