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获取被点击的元素以及子元素