Week six Homework

Source: Internet
Author: User

Off Topic:

1) Spit groove, as a person to see 37 knots, to do this week's work, can imagine the difficulty

2) Many of the files in the exercise do not exist on my system, so I will use the format approximation file as an alternative

3) I swapped the position of the third and second question, without affecting the test



Content of this week's job:

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;

Ideas

1) Vim editor Internal instruction add

2) Use the SED command to add

Copy the file first,there is no/etc/rc.d/rc.sysinit this file on Fedora 23, I use/etc/rc.d/init.d/functions this file to replace

Cp/etc/rc.d/init.d/functions/tmpvim/tmp/functions# then enter the following:%[email protected]\ (^[[:space:]]\+\) @#\[email Protected

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/87/1F/wKioL1fVEwnhYKD9AAEcFSQkYlA075.png "title=" 2016-09-11 16-15-25 screen. png "alt=" Wkiol1fvewnhykd9aaecfsqkyla075.png "/>

Exit does not save


Now use the SED command to replace

Sed-i-R "s/(^[[:space:]]+)/#\1/g"/tmp/functions

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/87/21/wKiom1fVGZPRsKxGAADYo6rlVbg443.png "title=" 2016-09-11 16-44-37 screen. png "alt=" Wkiom1fvgzprskxgaadyo6rlvbg443.png "/>



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

Using/tmp/functions as a demonstration, in the first question has been added to the # number


It's still two ways of thinking.

Vim:

:%[email protected]^#\ ([[: Space:]]\+\) @\[email protected]

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/87/1F/wKioL1fVH8DgaclbAAEWOWgSAqU482.png "title=" 2016-09-11 17-11-06 screen. png "alt=" Wkiol1fvh8dgaclbaaewowgsaqu482.png "/>


Exit does not save


Sed:

Sed-i-R "s/^#[[:space:]]+//g"/tmp/functions

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/87/22/wKiom1fVIUiRFohnAADLtePtQGY996.png "title=" 2016-09-11 17-17-45 screen. png "alt=" Wkiom1fviuirfohnaadlteptqgy996.png "/>


2, copy/boot/grub/grub.conf to/tmp directory, delete the blank character of the beginning of the/tmp/grub.conf file;

Use the new/tmp/functions as a demo

Copy a new functions to/tmp

Cp/etc/rc.d/init.d/functions/tmp


Vim:

:%[email protected]^[[:space:]]\[email Protected]@g

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/87/22/wKiom1fVJwCRvQbYAAEWzdG1GoQ730.png "title=" 2016-09-11 17-42-13 screen. png "alt=" Wkiom1fvjwcrvqbyaaewzdg1goq730.png "/>

Exit does not save


Sed

Sed-i-R "s/^[[:space:]]+//g"/tmp/functions

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/87/20/wKioL1fVJ6LQHFxwAADLziywc8U586.png "title=" 2016-09-11 17-44-49 screen. png "alt=" Wkiol1fvj6lqhfxwaadlziywc8u586.png "/>


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

Using/tmp/functions as a demonstration, first remove the # and spaces at the beginning of all lines

Sed-i-R "s/^#[[:space:]]*//g"/tmp/functions


Vim

: 1,[email protected]\ (. *\) @#\[email protected]

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/87/22/wKiom1fVKRjB7ZTjAADSIY5Ng8o952.png "title=" 2016-09-11 17-50-50 screen. png "alt=" Wkiom1fvkrjb7ztjaadsiy5ng8o952.png "/>

Exit does not save (fan-like highlighting


Sed

Sed-i-R "1,3s/(. *)/#\1/g"/tmp/functions

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/87/22/wKiom1fVKtbzTmb_AAB5dZ5w-cE535.png "title=" 2016-09-11 17-58-09 screen. png "alt=" Wkiom1fvktbztmb_aab5dz5w-ce535.png "/>




5. Change the last 0 of all enabled=0 or gpgcheck=0 in the/etc/yum.repos.d/centos-media.repo file to 1;


Using/etc/yum.repos.d/fedora.repo to copy to/TMP as a demo

Copying files

Cp/etc/yum.repos.d/fedora.repo/tmp


Vim (17 rows and 28 rows

:%[email protected]\ (enabled=\|gpgcheck=\) [email protected]\[email protected]

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/87/23/wKiom1fVPJfhLxjzAAFCudbgRwE757.png "title=" 2016-09-11 19-14-20 screen. png "alt=" Wkiom1fvpjfhlxjzaafcudbgrwe757.png "/>



Sed (the delimiter in the original SED is also free to change

Sed-i-R "[email protected] (enabled=|gpgcheck=) [email protected]\[email protected]"/tmp/fedora.repo

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/87/23/wKiom1fVPbixoc2_AACiwyZJdJs256.png "title=" 2016-09-11 19-19-01 screen. png "alt=" Wkiom1fvpbixoc2_aaciwyzjdjs256.png "/>


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

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

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

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


I wrote about Crontab's blog a long while ago, this is the link: http://www.cnblogs.com/divent/p/5743008.html


Create the files needed for backup (folder)

Mkdir/backuptouch/stats/memory.txt

Use CRONTAB-E to open the configuration file and edit

According to the sequence of questions

0 */4 * * */bin/cp-a/etc/backup/etc-$ (date +\%y\%m\%d\%h\%m) 0 0 * * 2,4,6/bin/cp/var/log/messages/backup/messages_l ogs/messages-$ (date +\%y\%m\%d) 0 */2 * * */bin/grep "^s"/proc/meminfo >>/stats/memory.txt# assumed working time Monday to Friday 8-12 14-18 0 8-12/2 * * 1-5/bin/echo "Howdy" 0 14-18/2 * * 1-5/bin/echo "Howdy"



Script Programming Exercises

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

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

Script Name: mage-test

#!/bin/bash# auther:divent# 2016-09-11 19:44:14# mage script Test10-11dirname= "testdir-$ (date +\%y\%m\%d\%h\%m)" mkdir /tmp/$dirnamefor i in {1..100};d otouch/tmp/$dirname/file$idone

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/87/24/wKiom1fVVQPyZh4kAADU-8rWCfE178.png "title=" 2016-09-11 20-58-32 screen. png "alt=" Wkiom1fvvqpyzh4kaadu-8rwcfe178.png "/>




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

Ideas :

1) using SED, enter 2 rows at a time, then delete the first row

Sed ' 1~2d '/etc/passwd | Cut-d ":"-F 1

2) Use awk to remove even rows

awk ' nr%2==0 '/etc/passwd | Cut-d ":"-F 1

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/87/25/wKiom1fVYhDBOKFQAACs46fvnTQ543.png "title=" 2016-09-11 21-53-58 screen. png "alt=" Wkiom1fvyhdbokfqaacs46fvntq543.png "/>


3) algorithm, using script, to remove even rows based on algorithm limit (assuming that awk and SED are not used

Script Name: Mage-test2

#!/bin/bash# auther:divent# 2016-09-11 20:08:31# mage script test12# get/etc/passwd's Maximum row maxline=$ (wc-l/etc/passwd | cut -D ""-F 1) # from 1 cycles to maximum line for I in $ (seq 1 $maxline);d o #取余, used to determine n=$[$i%2]if ["$n"-eq "0"];then #如果是偶数, then The number of lines shown in I, using head and tail to display the corresponding line, using cut to cut out the user name echo-e "\n$ (head-n $i/etc/passwd | Tail-n 1 | Cut-d ":"-F 1) "Fidone


650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/87/25/wKiom1fVYmaQs-zJAABzSiw1dGs462.png "title=" 2016-09-11 21-55-30 screen. png "alt=" Wkiom1fvymaqs-zjaabzsiw1dgs462.png "/>


13. Create 10 user user10-user19, password and user name;

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

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

Script Name: Mage-test3

#!/bin/bash# auther:divent# 2016-09-11 21:57:43# Mage script Test 13-15# Create a loop of 10 to 19 for I in $ (seq);d o# Create user Useradd "User$i" # Set password echo "User$i" | passwd--stdin "user$i" # Create file touch/tmp/file$i# Modify Permissions Chown "user$i": "User$i"/tmp/file$idone


650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/87/23/wKioL1fVZbLwi4YRAAE4SRXJQNI042.png "title=" 2016-09-11 22-07-16 screen. png "alt=" Wkiol1fvzblwi4yraae4srxjqni042.png "/>

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/87/25/wKiom1fVZcDQM7zkAAC1NCu-ChA955.png "title=" 2016-09-11 22-07-55 screen. png "alt=" Wkiom1fvzcdqm7zkaac1ncu-cha955.png "/>





This article from "divent" blog, declined reprint!

Sixth week 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.