linux 脚本 之 简化工作
来源:互联网 发布:windows屏保 编辑:程序博客网 时间:2024/06/16 05:25
#!/bin/bash
####调用另一个命令,生成0-23点的不同时间的报告,之前都是在前台要进行24个报告的添加,点击量挺多的,尤其是每次测试时都要重复点击。
str2='", "start_hour":'
str3=', "flag": 1, "start_minute": 0, "type": 1, "template": 1}, "user": {"host": "10.64.29.145", "from": "WebUI", "name": "admin"}}'
str=""
f=aalfyzoe_1938hfuy03417924024520801.testtest #临时文件名,防止文件重名,起一个怪名字
if [ -a $f ];then
echo "$f has existed!!"
while true;do
read -p "continue to use the file as input file??Y/N:"
case $REPLY in # REPLY 是read 的读取值的存储变量,系统定义的
y|Y)
echo "will use the file as input file"
break;;
n|N)
echo "program exit"
exit 1;;
*) # case 语法中默认处理
continue;;
esac
done
fi
#调用形式为 ./文件名 -n 1,2,3 或者 ./文件名 -n -1, 其他调用,比如 参数为 -d 1,2,3 或者-n -m 1,2都是错的
while getopts :n: name #第一个冒号表示忽略错误警示输出(当选项不是n时就会报错),n是选项,后面紧跟冒号表示该项需要跟随一个 值
do
case $name in
n)
oldIFS=$IFS
IFS=','
substrs=($OPTARG) # 上面的IFS 是系统变量, 这里的substrs就是把变量OPTARG的内容按照逗号分隔符,分割为一个数组,比如"1,2,3" 分割为数组(1 2 3)
for substr in ${substrs[@]} #数组操作 用 @或者* 可以取到整个数组内容, ${#a[@]} 可以取到数组长度
do
echo "$substr" | grep "^[0-9]*$" > /dev/null #判断一个字符串是否为数字
if [ $? -ne 0 ];then
echo "the number $substr is not number"
exit 2
fi
done
for substr in ${substrs[@]}
do
echo "the number is : $substr"
if [ $(($substr)) -eq -1 ];then
number=24
i=0
stri=""
while [ $i -lt $number ]
do
stri="$i"
len=$(expr length $stri) #求字符串长度
if [ $len -eq 1 ];then
stri="0$stri"
fi
str="$str1$stri$str2$i$str3"
echo "$str" > $f
i=$((i+1))
python /usr/vtm/pyscript/interface/ctmpyint.py < $f #调用命令执行工作的任务
done
elif [ $((substr)) -ge 0 -a $((substr)) -lt 24 ];then #计算数值表达式的值是否在0-23之间
len=$(expr length "$substr")
stri="$substr"
if [ $len -eq 1 ];then
stri="0$substr"
fi
str="$str1$stri$str2$substr$str3"
echo "$str" > $f
python /usr/vtm/pyscript/interface/ctmpyint.py < $f
fi
done
;;
\?) # 非 n 选项会被赋值为 ?
echo "invalid options$substrs"
echo "useage add_dailyReport.sh -n 1,2,4 or add_dailyReport.sh -n -1 to add 1 and 2 and 4 or 0~23"
break;;
*)
echo "unknow error the argument:$substr"
break;;
esac
done- linux 脚本 之 简化工作
- 使用脚本简化工作
- Linux 简化ssh登录的脚本
- 用脚本来简化iOS美术同学的工作
- 用脚本来简化iOS美术同学的工作
- 简化脚本
- 简化工作的利器
- 工作学习之---linux
- linux之bash脚本
- linux之ARP脚本
- Linux之shell脚本
- 管理系统前台工作简化
- COM---编程工作的简化
- Clear Case脚本简化操作
- Moto Linux应用开发(三):利用samba和telnet简化调试工作
- 开发自己的Maven插件之二:利用创建向导简化工作
- ◎Vbs脚本编程简明教程之九—妙用SendKeys简化重复操作
- linux 工作队列之API
- win7安装vmware8.0后键盘鼠标不起作用
- iOS基础笔记
- 每日一Lua(5)-迭代器与泛型for
- c++ noteII
- 学习c++的50条忠告(初学者必看)
- linux 脚本 之 简化工作
- LetoDMS文档管理系统配置LDAP认证
- 快速写出二叉树的遍历顺序
- 关于字符集和编码
- C++ NEW的使用及 基类指针转换成派生类指针 及static_cast和dynamic_cast的说明
- 【SCOI2010】【二分图最大匹配】游戏
- use-a, has-a, is-a和实现关系 介绍
- VIM使用进阶技巧
- 开发中总结的一些细节问题