小编San*_*San的帖子

在shell脚本中添加使用内容而不使用getopts

我有脚本,我需要显示使用命令,以防用户在执行脚本时错过任何必要的信息.

Usage : Script -s <server> -i <instance> -u <user> -p <password> <query> -w <warning value> -c <critical value>
Run Code Online (Sandbox Code Playgroud)

随着所有的解释 OPTIONS

我从参数中得到的值如下变量时尚.但我希望在shell脚本中使用此验证.

SERVER=$1
INSTANCE=$2
USER=$3
DB_PASSWD=$4
QUERY=$5
VAL_WARN=$6
VAL_CRIT=$7
Run Code Online (Sandbox Code Playgroud)

我尝试过使用getopts,但由于在传递值之前<query>没有-q参数,因此无法使用.

我已经尝试找到所有其他方法,但每个人都建议getopts这对我来说不是可行的解决方案.

请帮我这个..

unix linux shell getopts

10
推荐指数
1
解决办法
3万
查看次数

使用awk以编号格式将单行拆分为多行

我正在尝试使用awk命令将值拆分为三个部分.需要帮助打破3.

内容= 1. 11683 (<server01>: du.size[/,free] : 0.5 % 2. 21683 (<server02>: du.size[/,free] : 1.5 % 3. 31683 (<server03>: du.size[/,free] : 3.5 %

我希望上面的内容在编号系统中分成3行.

需要样品输出:

1. 11683 (<server01>: du.size[/,free] : 0.5 % 
2. 21683 (<server02>: du.size[/,free] : 1.5 % 
3. 31683 (<server03>: du.size[/,free] : 3.5 %
Run Code Online (Sandbox Code Playgroud)

我尝试过以下命令:

echo $content | awk -F"3. " '{ print $2 }' 
Run Code Online (Sandbox Code Playgroud)

我明白了

31683 (<server03>: du.size[/,free] : 3.5 %
Run Code Online (Sandbox Code Playgroud)

与其他人类似,但仍未能以正确的编号格式获得样本输出,如上所示.

谁可以帮我这个事 ?

linux shell scripting awk awk-formatting

4
推荐指数
1
解决办法
9243
查看次数

标签 统计

linux ×2

shell ×2

awk ×1

awk-formatting ×1

getopts ×1

scripting ×1

unix ×1