您应该使用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