Exercise question 4,

Source: Internet
Author: User
Tags egrep

Exercise question 4,
Chapter 5 exercise question 1st package the site directory/var/www/html to the/data directory at every night (it is best to generate different backup packages by time for each backup) 1.1.1 test command

[Root @ znix ~] # Cd/& tar zcf/data/www _ 'date must be f'.tar.gz var/www/html

1.1.2 writing to the script

[Root @ znix/] # cat/server/scripts/www. sh

Cd/& tar zcf/data/www _ 'date ready before f'.tar.gz var/www/html

1.1.3 test script

[Root @ znix ~] # Sh/server/scripts/www. sh

1.1.4 write scheduled tasks

[Root @ znix/] # crontab-l | tail-2

#### Backup/var/www/html dir

00 00 ***/bin/sh/server/scripts/www. sh>/dev/null 2> & 1

1.1.5 check execution result

[Root @ znix ~] # Ll/data/

Total 16

-Rw-r -- 1 root 154 Sep 11 www_2017-09-11.tar.gz

1.2 come to the old boy to study here at a.m. And a.m. (execute the program/server/script/oldboy. sh instead ).

00 9,14 **/bin/sh/server/scripts/oldboy. sh>/dev/null 2> & 1

0 indicates Sunday

6 indicates Saturday

1.3 describe the content of the following paths.

/Etc/sysctl. conf System Kernel configuration file

/Etc/rc. local boot

The ing between/etc/hosts ip address and domain name resolves the Host Name

/Etc/fstab automatic mounting upon startup

/Var/log/secure user login information, mainly to view the Failed

1.4 Indicate the meanings of the following grep Regular Expressions

^ Rows starting...

$ Rows ending...

. (Point number) any character

\ Escape Character \ n \ t

* The previous character exercises appear 0 or more times

The previous character {n, m} appears consecutively, at least n times, at most m

[^ T] retrieve records that do not contain t

^ [^ T] starting with not t

1.5 exclude empty lines and spaces in the file 1.5.1.

[Root @ znix ~] # Cat-A mun.txt

Znix1 $

Znix2 $

Znix3 $

$

Znix4 $

$

Znix5 $

$

Znix6 $

1.5.2 egrep Method

Locate the empty row-v parameter exclusion

[Root @ znix ~] # Egrep-n "^ * $" mun.txt

4:

6:

8:

10:

14:

[Root @ znix ~] # Egrep-n "^ $ | ^ + $" mun.txt

4:

6:

8:

10:

14:

1.5.3 awk Method

[Root @ znix ~] # Awk '! /^ [] * $/'Mun.txt

Znix1

Znix2

Znix3

Znix4

Znix5

Znix6

1.6 extract the content of the 1.6.1 file from the first column of passwd.txt.

[Root @ znix ~] # Cat passwd.txt

Root: x: 0: 0: root:/bin/bash

Bin: x: 1: 1: bin:/sbin/nologin

Daemon: x: 2: 2: daemon:/sbin/nologin

Adm: x: 3: 4: adm:/var/adm:/sbin/nologin

Lp: x: 4: 7: lp:/var/spool/lpd:/sbin/nologin

Sync: x: 5: 0: sync:/sbin:/bin/sync

1.6.2 excluding ideas

[Root @ znix ~] # Egrep "^ [^:] +" passwd.txt-o

Root

Bin

......

1.6.3 sed Method

[Root @ znix ~] # Sed-r's # (^. *) (: x. * :) (. *) # \ 3 \ 2 \ 1 # G' passwd.txt

/Bin/bash: x: 0: 0: root:/root: root

/Sbin/nologin: x: 1: 1: bin:/bin: bin

......

Exclude rows not starting:

[Root @ znix ~] # Sed-r's # (^ [^:] +) (. * :) (/. * $) # \ 3 \ 2 \ 1 # 'passwd.txt

/Bin/bash: x: 0: 0: root:/root: root

/Sbin/nologin: x: 1: 1: bin:/bin: bin

......

1.6.4 awk Method

Variables in awk:

-VOFS = ":"

The content of OFS is:

The delimiter between each column when awk displays the content of each column

-V modify and create variables available for awk

[Root @ znix ~] # Awk-F:-vOFS = ":" '{print $ NF, $2, $3, $4, $5, $6, $1}' passwd.txt

/Bin/bash: x: 0: 0: root:/root: root

/Sbin/nologin: x: 1: 1: bin:/bin: bin

......

1.7 vi/vim commands and shortcut keys

 Description

Command

Exit save

: Wq

Exit and force save ,!Mandatory

: Wq!

Force exit, not save

: Q!

Save

: Q/tmp /****

Move cursor to the last line of the file

G

Move cursor to the first line of the file

Gg

Move the cursor to 100 of the file.Line

100gg 100G: 100

Move the cursor from the cursor position to the beginning of the current row

0 ^

Move the cursor from the cursor position to the end of the current row

$

Delete the content of the current row

Dd

Delete the content of the last row from the current row to the file

DG

Delete the content of the first line from the current row to the file

Dgg

Paste

P

Paste 10Times

10 p

Copy

Yy

Cancel the last action

U

Delete a row

Dd

/Search content

Continue to search n

Continue to search for N

Search up

?

Deselect the highlighted content.

: Noh

1.7.1 edit services locates row 100th and copies the row to the last row of the file 10 times.

100gg

Yy

G

10 p

1.8 grant permissions to the oldboy directory and Its subdirectories 755.

Chmod-R 755 oldboy

1.9 change the owner of the oldboy directory and its sub-directories to oldboy and change the group to root.

Chown oldboy. lodboy oldboy.txt

1.9.1 possible errors during Modification

[Root @ znix ~] # Id oldboy

Uid = 500 (oldboy) gid = 501 (incahome) groups = 501 (incahome)

[Root @ znix ~] # Chown oldboy. oldboy oldboy-new.txt

[Root @ znix ~] # Chown oldboy. oldboy num.txt

Chown: invalid user: 'oldboy. oldboys'

Check whether the oldboy user exists and whether the oldbo user group exists

1.10 describe the role of umask.

Umask manages linux Default Permissions

Instance 1-1 when umask is 021

The file Permission is 644.

666-021 + 001 = 644

The dir permission is 756.

777-021 = 756

1.11 package/etc/rc. local/etc/hosts/etc/services to the/backup Directory every day. 1.11.1 test command

Root @ znix ~] # Cd/& tar zcf/backup/file 'date ready before f'.tar.gz etc/rc. local etc/hosts etc/services

Oot @ znix/] # ll/backup/file2017-09-11.tar.gz

-Rw-r -- 1 root 127455 Sep 11 :41/backup/file2017-09-11.tar.gz

1.11.2 write script

[Root @ znix/] # cat/server/scripts/file. sh

Cd/& tar zcf/backup/file 'date ready before f'.tar.gz etc/rc. local etc/hosts etc/services

1.11.3 test script

[Root @ znix/] # sh/server/scripts/file. sh

[Root @ znix/] # ll/backup/file2017-09-11.tar.gz

-Rw-r -- 1 root 127455 Sep 11/backup/file2017-09-11.t

[Root @ znix/] # cat/server/scripts/file. sh

1.11.4 write scheduled tasks

### Beifen zhongyaowenjan

00 00 ***/bin/sh/server/scripts/file. sh>/dev/null 2> & 1

1.11.5 test a scheduled task

[Root @ znix ~] # Date-s '23: 59: 29'

Mon Sep 11 23:59:29 CST 2017

[Root @ znix ~] # Ll/backup/file2017-09-1 *

-Rw-r -- 1 root 127455 Sep 11/backup/file2017-09-11.tar.gz

-Rw-r -- 1 root 127455 Sep 12 2017/backup/file2017-09-12.tar.gz

Chapter 2 review course 2nd scheduled tasks package/etc/services files to/tmp every two hours (it is best to back up the files into different backup packages each time) 2.1.1 test commands

[Root @ znix ~] # Cd/&/bin/tar zcf/tmp/ser _ 'date ready 1_f_1_h'.tar.gz etc/services

2.1.2 put in the script

[Root @ znix ~] # Cat/server/scripts/ser. sh

Cd/&/bin/tar zcf/tmp/ser _ 'date ready 1_f_1_h'.tar.gz etc/services

2.1.3 test script

[Root @ znix ~] # Sh/server/scripts/ser. sh

2.1.4 write scheduled tasks

[Root @ znix ~] # Crontab-l | tail-2

# Backup/etc/services

00 */2 ***/bin/sh/server/scripts/bak-ser.sh>/dev/null 2> & 1

2.1.5 check whether the scheduled task is successful

1) check whether the package is successful. Check whether append information exists in the file.

2) view the scheduled task log/var/log/cron

2.2 unable to connect to linux 2.2.1

Ping IP Address

Solution to ping failure of instance 2-1:

Is the IP address of the server correct?

Whether the server Nic is started, that is, whether ONBOOT is yes

System Nic Configuration

Instance 2-2 VMware related:

Vmware-5 services started?

Vmware configuration-whether the NIC is connected

Check whether your vmware Nic's vmnet8 has been started

2.2.2 is there a financial threat?

Check whether iptables selinux is disabled

2.2.3 whether a service is provided

Instance 2-3 check whether port 22 is enabled

Method 1: telnet 10.0.0.200 22

Method 2: ss-lntup | grep 22

Whether the process of instance 2-4 is running

Ps-ef | grep sshd

2.3 what if linux cannot access the Internet 2.3.1 ping the Domain Name

The domain name cannot be pinged.

[Root @ znix ~] # Ping centos.houzhaoshun.cn

Ping: unknown host centos.houzhaoshun.cn

 

2.3.2 ping the Internet ip Address

Ping allowed

[Root @ znix ~] # Ping 123.206.66.149

PING 123.206.66.149 (123.206.66.149) 56 (84) bytes of data.

64 bytes from 123.206.66.149: icmp_seq = 1 ttl = 128 time = 63.1 MS

64 bytes from 123.206.66.149: icmp_seq = 2 ttl = 128 time = 60.5 MS

2.3.3 check the dns configuration file

[Root @ znix ~] # Cat/etc/resolv. conf

2.3.4 modify the configuration file

Modify and restart the NIC to take effect

[Root @ znix ~] # Service network restart

Shutting down interface eth0: [OK]

Shutting down loopback interface: [OK]

Bringing up loopback interface: [OK]

Bringing up interface eth0: Determining if ip address 10.0.0.201 is already in use for device eth0...

[OK]

2.4 check whether a software package is installed according to rpm related 2.4.1

[Root @ znix ~] # Rpm-qa tree

Tree-1.5.3-3.el6.x86_64

2.4.2 query the content in the Software Package

[Root @ znix ~] # Rpm-ql tree

/Usr/bin/tree

/Usr/share/doc/tree-1.5.3

/Usr/share/doc/tree-1.5.3/LICENSE

/Usr/share/doc/tree-1.5.3/README

/Usr/share/man/man1/tree.1.gz

2.4.3 query the software package of a command

Use absolute path when querying

[Root @ znix ~] # Rpm-qf 'which crond'

Cronie-1.4.4-16.el6_8.2.x86_64

 

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.