shell脚本,主要是对输入参数检验
usage()
{
echo "\nUSAGE:\n"
echo "PmActivityReport.sh\t-type\t<latency|activity>\t\t\t(Mandatory)\t/*Report type.*/\n"
echo "\t\t\t-ne\t<RNC-IN|RNC-AN|RNC-CN|BTS|ALL>\t\t(Optional)\t/*Ne type.*/\n"
echo "\t\t\t-from\t<YYYY/MM/DD-HH:00>\t\t\t(Optional)\t/*Begin time.*/\n"
echo "\t\t\t-to\t<YYYY/MM/DD-HH:00>\t\t\t(Optional)\t/*End time.*/\n"
echo "\t\t\t-o\t<>\t\t\t\t\t(Optional)\t/*Output file name.*/\n"
echo "\nNOTE:\n"
echo "The default value of the ne type is \"ALL\"."
echo "The default value of the output file name is \"latencyReport.txt\" or \"activityReport.txt\", depending on the report type."
echo "Time must be given in a strict format: YYYY/MM/DD-HH:MM. Only full time is allowed, and the minutes can not be set different from \"00\".\n"
}
if [ $# -lt 2 ]
then
usage
else
reportType="UNKNOWN"
neType="ALL"
fromTime="UNKNOWN"
toTime="UNKNOWN"
output="UNKNOWN"
totalPara=$#
para=1
paraIsValid=1
while [ $para -le $totalPara ]
do
case "$1" in
-type)
if [ "$2" = "latency" -o "$2" = "activity" ]
then
reportType=$2
else
echo "Wrong parameter for -type!"
paraIsValid=0
fi
;;
-ne)
if [ "$2" = "RNC-IN" -o "$2" = "RNC-AN" -o "$2" = "RNC-CN" -o "$2" = "BTS" -o "$2" = "ALL" ]
then
neType=$2
else
echo "Wrong parameter for -ne!"
paraIsValid=0
fi
;;
-from)
timeIsValid=`echo $2 | grep -c [0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]-[0-9][0-9]:00$`
if [ $timeIsValid -eq 1 ]
then
Year=`echo $2 | cut -c1-4`
Month=`echo $2 | cut -c6-7`
Day=`echo $2 | cut -c9-10`
Hour=`echo $2 | cut -c12-13`
if [ $Month -ge 13 ]
then
echo "Wrong parameter for -from! Please check the month."
timeIsValid=0
fi
if [ $Day -ge 32 ]
then
echo "Wrong parameter for -from! Please check the day."
timeIsValid=0
fi
if [ $Hour -ge 25 ]
then
echo "Wrong parameter for -from! Please check the hour."
timeIsValid=0
fi
if [ $timeIsValid = 1 ]
then
timeFrom=$2
else
paraIsValid=0
fi
else
echo "Wrong parameter format for -from!"
paraIsValid=0
fi
;;
-to)
timeIsValid=`echo $2 | grep -c [0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]-[0-9][0-9]:00$`
if [ $timeIsValid -eq 1 ]
then
Year=`echo $2 | cut -c1-4`
Month=`echo $2 | cut -c6-7`
Day=`echo $2 | cut -c9-10`
Hour=`echo $2 | cut -c12-13`
if [ $Month -ge 13 ]
then
echo "Wrong parameter for -to! Please check the month."
timeIsValid=0
fi
if [ $Day -ge 32 ]
then
echo "Wrong parameter for -to! Please check the day."
timeIsValid=0
fi
if [ $Hour -ge 25 ]
then
echo "Wrong parameter for -to! Please check the hour."
timeIsValid=0
fi
fromTimeValue=`echo $timeFrom | sed -e "s/\///g" | sed -e "s/-//" | sed -e "s/://"`
toTimeValue=`echo $2 | sed -e "s/\///g" | sed -e "s/-//" | sed -e "s/://"`
if [ $toTimeValue -le $fromTimeValue ]
then
echo "Wrong parameter for -to! The time for -to is not later than that for -from."
timeIsValid=0
fi
if [ $timeIsValid = 1 ]
then
timeTo=$2
else
paraIsValid=0
fi
else
echo "Wrong parameter format for -to!"
paraIsValid=0
fi
;;
-o)
if [ "$2" != "" ]
then
output=$2
else
echo "Wrong parameter for -o!"
paraIsValid=0
fi
;;
*)
echo "Bad option \"$1\"."
paraIsValid=0
;;
esac
para=`expr $para + 2`
shift
if [ $# -gt 1 ]
then
shift
fi
done
if [ $paraIsValid -eq 0 -o $reportType = "UNKNOWN" ]
then
usage
else
if [ $reportType = "latency" ]
then
output="latencyReport.txt"
fi
if [ $reportType = "activity" ]
then
output="activityReport.txt"
fi
fi
fi
shell脚本,主要是对输入参数检验的更多相关文章
- shell脚本编程-处理用户输入
命令行参数 命令行参数:允许在运行脚本时向命令行添加数据值 如:$ ./addem 10 30 读取参数 bash shell会将一些称为位置参数的特殊变量分配给命令行输入的所有参数,甚至包括shel ...
- shell脚本中的交互式输入自动化
shell中有时我们需要交互,但是呢我们又不想每次从stdin输入,想让其自动化,这时我们就要使shell交互输入自动化了. 1 利用重定向 重定向的方法应该是最简单的 例: 以下的te ...
- shell脚本,提示用户输入一个用户名,如果存在;显示用户UID和SHELL信息;否则,则显示无此用户;显示完成之后,提示用户再次输入;如果是quit则退出;
[root@localhost wyb]# cat tishiuser.sh #!/bin/bash #提示用户输入一个用户名,如果存在:显示用户UID和SHELL信息:否则, #则显示无此用户:显示 ...
- shell脚本实现算术运算且输入的不能为非数字的值
#!/bin/bash c= ] do echo "请输入第一个数" read a echo "请输入第二个数" read b ]* ]] && ...
- shell脚本read -t 超时输入测试
[root@server0 shellStudy]# cat timeout.sh #!/bin/bash TIMEOUT=3 #超时间隔 echo "What is your name?& ...
- 《Linux命令行与shell脚本编程大全》第十一章 构建基本脚本
11.1使用多个命令 $date;who // 命令列表,加入分号就可以,这样会依次执行.参见5.2.1节 注意区分$(date;who),这个是进程列表,会生成一个子shell来执行 Shel ...
- 常用shell脚本
[脚本1]打印形状打印等腰三角形.直角三角形.倒直角三角形.菱形 #!/bin/bash # 等腰三角形 read -p "Please input the length: " n ...
- 【转】干货分享-100个shell脚本
本文用于记录学习和日常中使用过的shell脚本 [脚本1]打印形状 打印等腰三角形.直角三角形.倒直角三角形.菱形 #!/bin/bash # 等腰三角形 read -p "Please i ...
- 如何使用zx编写shell脚本
前言 在这篇文章中,我们将学习谷歌的zx库提供了什么,以及我们如何使用它来用Node.js编写shell脚本.然后,我们将学习如何通过构建一个命令行工具来使用zx的功能,帮助我们为新的Node.js项 ...
- Shell脚本中判断输入参数个数的方法投稿:junjie 字体:[增加 减小] 类型:转载
Shell脚本中判断输入参数个数的方法 投稿:junjie 字体:[增加 减小] 类型:转载 这篇文章主要介绍了Shell脚本中判断输入参数个数的方法,使用内置变量$#即可实现判断输入了多少个参数 ...
随机推荐
- 轨道控制器 threejs
就是一个可以360转动的相机,通过不断的改变相机的参数 然后渲染达到效果. // 引入相机控件 -- 轨道控制器 // console.log('OrbitControls',OrbitContro ...
- mysql进阶-锁
锁 概述 锁是计算机协调多个进程或线程并发访问某一资源的机制.在数据库中,除传统的计算资源(CPU.RAM.I/O)的争用以外,数据也是一种供许多用户共享的资源. 如何保证数据并发访问的一致性.有效性 ...
- 探索 PCI 转 PMC 载板转接卡:连接不同接口的桥梁
探索 PCI 转 PMC 载板转接卡:连接不同接口的桥梁 在计算机硬件领域,各种接口和总线标准不断演进,以满足日益增长的性能和功能需求.在这个过程中,不同接口之间的转换设备应运而生,其中 PCI 转 ...
- java中如何将Object类型转换为int类型
如何将Object类型转换为int类型 Object object = null; try { Integer.parseInt(object.toString()); } catch (Number ...
- MindSponge分子动力学模拟——增强采样(2024.11)
技术背景 关于增强采样(Enhanced Sampling)算法的具体原理,这里暂不做具体介绍,感兴趣的童鞋可以直接参考下这篇综述文章:Enhanced sampling in molecular d ...
- Ubuntu安装Edge浏览器,好用的浏览器!!
秉持着简介的原则,我这里把重要的步骤记录下来,减少废话的使用量,大大缩短你们看的时间,好吧.. 步骤 首先,使用以下命令更新您的系统: sudo apt update 然后,使用以下命令安装Micro ...
- 模算术 modular arithmetic
https://en.wikipedia.org/wiki/Modular_arithmetic#Integers_modulo_n 模算术: 整数达到特定值时会' 折返 ' 回来-- 模数 modu ...
- 题解:CF1776L Controllers
CF1776L Controllers 题解 分析 先把题目形式化.设 \(n\) 次加减中有 \(x\) 个加,\(y\) 个减,其中 \(a\) 加了 \(u\) 次,减了 \(v\) 次,显然 ...
- downloadFile:base64数据导出文件,文件下载
function downloadFile(filename, data){ let DownloadLink = document.createElement('a'); if ( Download ...
- 小米R3G刷了padavan后时间不同步和定时关闭外网(wan)端口
怎么刷openwrt或者padavan请见我2022年3月份的帖子 https://www.cnblogs.com/jar/p/15954037.html 最近遇到个新环境,遂拿出来用用 有1个问题和 ...