shell脚本不暂停进程,暂停几秒执行下一条shell命令
生活随笔
收集整理的这篇文章主要介绍了
shell脚本不暂停进程,暂停几秒执行下一条shell命令
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
需求如下:
跑monkey脚本如果遇到异常结束,则使用logcat输出日志,输出三秒后停止输出
如果使用sleep 命令的话,则会导致logcat在sleep的时候也暂停执行了
解决方法如下,通过while循环暂停3秒:
ti1=`date +%s` #获取时间戳 ti2=`date +%s` i=$(($ti2 - $ti1 ))while [[ "$i" -ne "3" ]] doti2=`date +%s`i=$(($ti2 - $ti1 )) done
以下是我monkey脚本中实现的代码(monkey异常结束或正常结束后,会自动截取3秒的logcat 日志)
logcat -c #清除日志 monkey -p com.yixia.videoeditor --throttle 1000 -s 82 -v -v -v --pct-appswitch 20 --pct-majornav 10 --pct-touch 30 --pct-syskeys 10 --pct-motion 25 --pct-nav 5 20000 > /sdcard/monkey/monkey.log logcat -v time > /sdcard/monkey/logcat.log & # 如果执行monkey跑出问题异常结束 或者正常跑完monkey,则打印日志(只有3秒的日志获取时间)ti1=`date +%s` #获取时间戳 ti2=`date +%s` i=$(($ti2 - $ti1 )) while [[ "$i" -ne "3" ]] doti2=`date +%s`i=$(($ti2 - $ti1 )) donekill $! #结束后台运行的logcat进程 echo "----------------------- 测试完成标注!!! -----------------------" >> /sdcard/monkey/logcat.log
总结
以上是生活随笔为你收集整理的shell脚本不暂停进程,暂停几秒执行下一条shell命令的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: adb logcat 命令行用法
- 下一篇: js获取被点击的元素以及子元素