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-i ' s/\ (^[[:space:]]\)/#\1/g '/tmp/rc.sysinit
2, copy/boot/grub/grub.conf to/tmp directory, delete the blank character of the beginning of the/tmp/grub.conf file;
Sed-i ' s/^[[:space:]]\+//g '/tmp/grub.conf
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-i ' s/^#[[:space:]]\+//g '/tmp/rc.sysinit
4. Add # to the beginning of the first three lines in the/tmp/grub.conf file;
Sed-i ' 1,3s/\ (^.\)/#\1/g '/tmp/rc.sysinit
5. Change the last 0 of all enabled=0 or gpgcheck=0 in the/etc/yum.repos.d/centos-media.repo file to 1;
Sed ' s/enabled=0/enabled=1/g;s/gpgcheck=1/gpgcheck=2/g; '/etc/yum.repos.d/centos-media.repo
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
cat/home/backup/shell/crond_shell.sh#!/bin/bash# definition variable datetime= ' date +\%y\%m\%d\%h\%m ' baname=etc-quanlj= $Baname $ datetime.tar.gz# Package tar czf $QUANLJ/etc >/dev/nullmv $QUANLJ/backupcrontab-e00 */4 * * sh/home/backup/shell/crond_ Shell.sh >/dev/null
7, weekly 2,4,6 backup/var/log/messages file to/backup/messages_logs/directory, save the file name like messages-20160830
* * * * * 2,4,6/bin/cp/var/log/messages/backup/messages_logs/messages-' date +%y%m%d '
Note: Why is the variable name here to write the absolute path, because at the time of the execution of the scheduled task, you will find that the path of the command, but manual execution, which I do not understand why this.
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
Grep-e "^s"/proc/meminfo >>/stats/memory.txt
9, working days of work time, every two hours to perform the echo "Howdy"
Script Programming Exercises
Example 1:cat/home/backup/shell/echo_shell.sh#!/bin/bashecho "Howdy" Crontab-e * */2 * * 1-5 Sh/home/backup/shell/crond_ shell.sh Example 2: Use the simplest method as follows crontab-e* */2 * * 1-5/bin/echo "Howdy"
10, create the directory/tmp/testdir-the current date and time;
Mkdir/tmp/testdir-date +%f-%t
11. Create 100 empty files in this directory: file1-file100
Seq-f ' file%01g ' 1 100 | Xargs mkdir
12. Display the user name of the user who is located in the/ETC/PASSW D file in the first even row;
Sed-n ' n;p '/etc/passwd|cut-d:-f1
13. Create 10 user user10-user19, password and user name;
#!/bin/bashfor I in $ (seq-w) do useradd-s/bin/bash user10$i echo "Password$i" | md5sum | Tee-a Passwd.txt | passwd--stdin User$idone
14, create 10 empty files file10-file19 in/tmp/;
For i in ' seq ';d o touch/tmp/file$i;done;
15. Change the file10 and the genus to user10, and so on.
For in ' seq ';d o chown user$i.user$i/tmp/file$i;done;
This week's summary:
Finish the above homework found, familiar with the use of some of the commands, but also appeared, such as some of the parameters of Gerp, here, also repeated use up, below I do an archive for him.
Inspirational statement: Promotion to pay, empty gloves White wolf, like go out left to buy welfare lottery. Learning or need to work harder, more perseverance, to go through the process.
Grep:
One. Match characters
. matches any single character [] matches any character in the specified range [^] matches any character in the specified range [: Alpha:] alphabetic character [: Lower:] Lowercase alphabetic character [: Upper:] Uppercase character [:d Igit:] Number [: alnum:] alphanumeric character [: Space:] White space characters (prohibit printing), such as carriage returns, line breaks, vertical tabs and page breaks [:p UNCT:] punctuation characters [: Cntrl:] control characters (prohibit printing) [:p rint:] printable characters typically use two brackets when they are used.
1.^ Anchor Header grep "^r. T " /etc/passwd2.$ Anchor Line end grep " h$ " /etc/ passwd3.^$ anchor Blank line grep "^$" /etc/passwd4.\< (\b) anchor Word Header grep "\<r. T " /etc/passwd5.\> (\b) anchor word grep " R. T\> " /etc/passwd example (easy to confuse): Contains at least one blank character grep "[[: Space:]]\{1,\}" /etc/passwd contains at least one non-whitespace character grep "[^[:space:]]\{1,\}" &NBSP;&NBSP;/ETC/PASSWD does not have a blank character grep -v "[^[:space:]]\{1,\}" /etc/passwd6.\ (\) group characters grep "\ (L.. e\). *\1r "Example:grep --color " l\ ([13]\): \1:.*:\1 " /etc/inittab
Iii. Number of Matches
* Match the previous word Fuzhin once. * Match any character of any length (note that greedy mode, such as grep "R.*t"/etc/passwd) x\{m,n\} specifies that the preceding character appears at least m times and at most n times. X\{m,\} specifies that the preceding character appears at least m times x\{0,n\} specifies that the preceding character appears at most n Times x\{m\} exactly matches m times? Matches the preceding character 0 or 1 times the seq: usage: seq [options] ... Mantissa or: seq [options] ... First Count mantissa or: seq [options] ... The first number increment mantissa with the specified increment prints the number to the mantissa starting from the first number. -F, the--format= format uses the printf-style floating-point format-S, the--separator= string separates numbers using the specified string (by default: \ n)-W,--equal-width adds 0 before the column to make the same width
For
Example 1for variable do statement done example 2for variable in list do statement done
This article is from the "thinking under the roof" blog, please be sure to keep this source http://wuyanxxk.blog.51cto.com/4130666/1851881
The use of Linux regularization with SED