您應該使用bash
sleep
命令。摘自man
頁面: -
您可以在腳本中提供以等待5分鐘並執行操作。
NAME
sleep - delay for a specified amount of time
DESCRIPTION
Pause for NUMBER seconds. SUFFIX may be 's' for seconds (the default), 'm' for minutes, 'h' for hours or 'd' for days. Unlike most implementations that require NUMBER be an
integer, here NUMBER may be an arbitrary floating point number. Given two or more arguments, pause for the amount of time specified by the sum of their values.
一種合適的方式到你的解決辦法是: - 當ps -ef | grep -v grep | grep "tomcat7"
返回該條件通過命令成功錯誤代碼
#!/bin/bash
maxAttempts=0
maxCounter=2 # Number of attempts can be controlled by this variable
while [ "$maxAttempts" -lt "$maxCounter" ]; do
if ps -ef | grep -v grep | grep "tomcat7" > /dev/null
then
echo "tomcat7 service running, "
exit 1
else
maxAttempts=$((maxAttempts+1))
sleep 5m # The script waits for 5 minutes before exiting with error code '-1'
fi
done
exit -1
的if
條件的作品。 > /dev/null
將所有標準輸出(stdout,stderr)壓制爲/dev/null
,以便我們只能使用所提供的命令的退出代碼。
發佈您嘗試到現在爲止 – syadav