日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

shell脚本不暂停进程,暂停几秒执行下一条shell命令

發布時間:2025/3/21 54 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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命令的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。