[英]Script in crontab to be executed only if is equal or exceeds a value
I currently have a script in crontab for rsync (and some other small stuff). 我目前在crontab中有一个用于rsync的脚本(和其他一些小东西)。 Right now the script is executed every 5 minutes.
现在,脚本每5分钟执行一次。 I modified the script to look for a specific line from the rsync part (example from my machine, not the actual code):
我修改了脚本,以从rsync部分中查找特定行(从我的机器中查找示例,而不是实际代码):
#!/bin/bash
Number=`/usr/bin/rsync -n --stats -avz -e ssh 1/ root@127.0.0.1 | grep "Number of regular files transferred" | cut -d':' -f 2 | tr -d 040\054\012`
echo $Number
Let's say the number is 10. If the number is 10 or below I want the script executed through the crontab. 假设数字是10。如果数字是10或小于10,我希望通过crontab执行脚本。 But if the number is bigger I want to be executed ONLY manually.
但是,如果数字更大,我只想手动执行。
Any ides? 有想法吗?
Maybe you can use an argument to execute it manually, for example: 也许您可以使用参数来手动执行它,例如:
if [[ $Number -le 10 || $1 == true ]];then
echo "executing script..."
fi
This will execute if $Number
is less or equal to 10
or if you execute it with true
as the first positional argument, so if $Number
is greater than 10
it won't execute in your crontab and you can execute your script manually with ./your_script true
. 如果
$Number
小于或等于10
或以true
作为第一个位置参数执行它,则将执行此操作,因此,如果$Number
大于10
则它将不在crontab中执行,并且您可以使用手动执行脚本./your_script true
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.