Shell script learning-3 (Baidu shell script pen questions)

Source: Internet
Author: User

Question:

1.
Extract the rows that contain "warning" or "Fatal" and do not contain "ignor" from the. log file, and then extract the 5th fields separated ":".

2.
Write a script and only want to perform simple subtraction. A prompt is required to enter the variable.

3. Read the shell script (explain the functions executed below). Pick out the errors in the following program or script and describe the errors.

#! /Bin/bash

# Monitor whether the Point Port of cpuser is normal

LOGNAME = "/home/FORUM/log/lpointlog. WF"

Flagfile = "/home/FORUM/log/lognum.txt"

Lodnum = sed-n "1, 1 P" $ flagfile

Newnum = WC-L $ {LOGNAME}

Echo $ newnum> $ flagfile

Totalnum = expr $ newnum-$ oldnum

Tail-N $ totalnum $ LOGNAME | grep "point_thread warning"

If [$? = 0]

Then

Mail-s "cpuser point" port exception. Please handle it! "
Test@aa.com </dev/null

FI>

 

Answer:

 

1.

#! /Bin/bash
Awk-F: '{if ($0 ~ /(Warning | fatal)/& $0 !~ /Ignor/) {print $5} 'a. Log

2.

#! /Bin/bash
Read-P "input a num:" num1
Read-P "input another num:" num2
Result = 'expr $ num1-$ num2'
# Let "result = num1-num2"
# Let result = num1-num2
Echo $ result
~

3.

Use reverse quotation marks to replace the command line. If [$? = 0]
It should be written as if [$? = 0], used to determine whether the last command was successfully executed;

The last line should be>/dev/null, And the last line after the fi is removed.

Contents Directory: http://www.mythroad.net/tag/q_written_examination_and_interview_code_title/

More highlights from: Magic Bean road-mysterious road ahead, waiting for the fog http://www.mythroad.net

Related Article

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.