Unix Shell parsing 1

Source: Internet
Author: User
Tags dname


----Shell 1

testdb3:/home/oracle [Pprod] >more/home/oracle/utility/macro/tns_log_back_12c.sh
#! /usr/bin/ksh



#set-X


if [$# = 0]
Then
echo ""
echo "# Usage: $ TNS log file name"
echo ""
Else

# Set up the search paths:
Path= $PATH:.
Case $PATH in
*/usr/local/bin*);;
*:) Path=${path}/usr/local/bin;;
*) Path=${path}:/usr/local/bin;;
Esac
Export PATH

# Set up the Oracle variables:
Export Oracle_sid=pprod
Export ORACLE_BASE=/OPT/ORACLE12C
Export oracle_home=/opt/oracle12c/product/12.1
Export Oraenv_ask=no
. Oraenv

Export path= $ORACLE _home/bin:.: $PATH:/usr/bin:/usr/sbin:/etc
Export Ld_library_path=/usr/lib: $ORACLE _home/lib
Export ps1= ' hostname ': ' ${pwd} [$ORACLE _sid] > '
Export term=vt220
#export ora_nls33= $ORACLE _home/ocommon/nls/admin/data
Export Nls_lang=american_america. Zhs16gbk
#export Nls_lang=american_america. UTF8
#export nls_date_format= ' Mon DD YYYY HH24:MI:SS '
Umask 022



Date= ' Date +%y%m%d%h%m '

Tns_logname=$1
tns_logbak= ' hostname ' _${tns_logname}_ ' date ' +%y%m%d%h%m '
Tns_logpath=${oracle_home}/network/log

CD ${tns_logpath}
CP ${tns_logname} ${tns_logbak}
If [$?-ne 0]
Then
echo "${bold}error:back TNS log Error!${normal}"
echo ""
Exit 0
Fi
> ${tns_logname}
/usr/contrib/bin/gzip ${tns_logbak}
LS-LRT ${oracle_home}/network/log
Fi


--shell 2

testdb3:/home/oracle [Pprod] >more/home/oracle/utility/macro/compress_all.sh
Script_dir=/home/oracle/utility/macro
Prg_name= $SCRIPT _dir/compress_arch.sh
# $SCRIPT _dir/compress_arch_ngen.sh Ngenpr/ngprdblog 100 10
# $PRG _name Ngende/ngdedblog 10
# $PRG _name Ngenro/ngrodblog 10
# $PRG _name Ngenroa/ngroadblog 10
$PRG _name Topspr/topsprdblog 10
$PRG _name Gdpr/gdprdblog 10
# $PRG _name Ngenpr/ngenprdblog 10
$PRG _name Xprprod/xprproddblog 10
$PRG _name Pcc/pccdblog 10
$PRG _name Corpprod/corpproddblog 10
$PRG _name Bpsprod/bpsproddblog 10
$PRG _name Tgpsprod/tgpsproddblog 10
$PRG _name Wrlprod/wrlproddblog 24
$PRG _name Icomprod/icomproddblog 24
$PRG _name Bizprod/bizlinkdblog 10
#add in 20160901
$PRG _name Oasprod/oasprodlog 10

|

More compress_arch.sh

Oracle_sid=$1
Dname=$2
Compress=/usr/contrib/bin/gzip
Script_dir=/home/oracle/utility/macro

sleep= "/usr/bin/sleep"

# 1. Check whether DB is up and running on server
Up_flag= ' ${script_dir}/chkdbup.sh ${oracle_sid} '

If [${up_flag}-eq 0]; Then
Ls-t ${dname}/*.arc | Awk-v sleep= "${sleep}"-V compress=${compress} '
NR > Max {print COMPRESS, $0;system (SLEEP)}
' | Ksh-x


@@@ 解析 Shell2

1. awk [-parametric variable] ' begin{initialization} condition type 1{action 1} condition type 2{action 2} .... end{after processing} '
Where: The statements in begin and end play a role before starting to read the file (In_file) and after reading the file, which can be understood as initialization and wrap-up.
(1) Parameter description:
-F Re: Allows awk to change its field delimiter
-V var= $v assigns the V value to Var, if there are multiple variables to be assigned, then write multiple-V, each variable assignment corresponds to a-V
e.g. to print the line between the NUM line of file A and the Num+num1 line,
Awk-v num= $num-v num1= $num 1 ' nr==num,nr==num+num1{print} ' a
-F Progfile: Allows awk to invoke and execute the Progfile program file, of course Progfile must be a program file that conforms to the awk syntax.

2. The role of pipelines
The output of the following 2 commands can be compared, indicating that the pipeline is processed in a single line of records.
Ls-t/pproddblog/*.dbf*|more
Ls-t/pproddblog/*.dbf*


3.NR usage
NR NR is the total number of rows read
Conditional expression assigns a value to an expression using two symbols-question mark and colon: conditional expression1? Expression2:expressional3, whose logic is equivalent to conditional expressions in C. The corresponding If/else statements are as follows:
{
if (expression1)
Expression2
Else
Expression3
}
/> Cat Testfile
Northwest NW Charles Main 3.0.98 3 34
Western WE Sharon Gray 5.3.97 5 23
Southwest SW Lewis dalsass 2.7.8 2 18
Southern so Suan Chin 5.1.95 4 15
Southeast SE Patricia Hemenway 4.0.7 4 17
Eastern EA TB Savage 4.4.84 5 20
Northeast NE AM Main Jr. 5.1.94 3 13
North NO Margot Weber 4.5.89 5 9
Pal CT Ann Stephens 5.7.94 5 13

/> awk ' NR <= 3 {print ($7 > 4?) "High" $7: "Low" $7)} ' testfile
Low 3
High 5
Low 2

4.
Let's take a look at a brief introduction to the System () function:

#include
int system (const char *command)

The system () function calls/bin/sh to execute the command specified by the parameter,/bin/sh is typically a soft connection, pointing to a specific shell, such as the BASH,-C option, which tells the Shell to read the command from the String command, and during the command execution, SIGCHLD is blocked, like saying: Hi, kernel, this will not send me sigchld signal, and so on I am busy to say; During the command execution, SIGINT and sigquit are ignored, meaning that the process receives both signals without any action.

Unix Shell parsing 1

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.