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