Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 带cron的循环中多个条件中的If条件逻辑错误_Bash_Loops_If Statement_Cron_Logic - Fatal编程技术网

Bash 带cron的循环中多个条件中的If条件逻辑错误

Bash 带cron的循环中多个条件中的If条件逻辑错误,bash,loops,if-statement,cron,logic,Bash,Loops,If Statement,Cron,Logic,我需要在cron中运行2个循环,每5分钟运行一次 */5 * * *  * 按cron 1循环。每5分钟工作一次,检查文件是否上传。($Dayed表示具有回溯日期名称的文件) 第一个cron循环对我来说工作正常,第二个cron循环我无法解决,第二个循环有3个条件 FILE=/fullpath/$yesterday.zip if test -f "$FILE"; then touch /fullpath/loop2.txt ##########for loop 2 echo "I am the

我需要在cron中运行2个循环,每5分钟运行一次

*/5 * * *  *
按cron 1循环。每5分钟工作一次,检查文件是否上传。($Dayed表示具有回溯日期名称的文件)

第一个cron循环对我来说工作正常,第二个cron循环我无法解决,第二个循环有3个条件

FILE=/fullpath/$yesterday.zip
if test -f "$FILE"; then
touch /fullpath/loop2.txt ##########for loop 2
echo "I am the best"
else
cd /fullpath/
wget -r -np -nH "url/$yesterday.zip" ###########it should be 20+ mb file
find . -name "*.zip" -type 'f' -size -160k -delete ########## it will delete is some garbage downloaded
rm -rf /fullpath/loop2.txt  ########## delete the file so it stopped loop 2 for working evry 5 minutes .
fi

FILE2=/fullpath/loop2.txt
if test -f "$FILE2"; then
echo -e "Script will work only once" | mailx -v -s "Script will work only once"  myemail@gmail.com
else
echo "full script work"
touch /fullpath/loop2.txt
fi
1。当它昨天找到$zip时,它应该可以工作。zip

2。它应该在$beday.zip之后只工作一次(因为它的cron所以它在$beday.zip找到时每5分钟工作一次)

3。它应该在00:00前工作到$treaty.zip下载

($Dayed文件没有固定的下载时间,所以我每5分钟运行一次cron) 我做了这件事(写在下面是为了让你们知道。大家不要认为我没有努力,也不要说show sampel code,只需要一个带有cron的if语句,包括这3个条件)


你们可以忽略我上面的代码,简单地告诉我,对于这样的3个条件循环,我会使用这样的语句:

if lockfile -r0 /tmp/lockfile_$(date +%F); then #only run if there's no lockfile for the day
    cd /fullpath/
    # while we don't have a correct file (absent or truncated)
    while [[ ! -f "$yesterday.zip" ]] || [[ $(stat -c %s "$yesterday.zip") < 20971520 ]]; do
      wget -r -np -nH "url/$yesterday.zip"  # try to download it
      if [ $? -ne 0 ]; then # if the file isn't available yet
        rm /tmp/lockfile_$(date +%F) # delete the lock in order to attempt the download again in 5"
      fi
    done
fi
if lockfile-r0/tmp/lockfile_$(日期+%F);然后#只有当天没有锁定文件时才运行
cd/完整路径/
#而我们没有正确的文件(缺少或被截断)
而[[!-f“$forday.zip”]|[[$(stat-c%s“$forday.zip”)<20971520];做
wget-r-np-nH“url/$forday.zip”#尝试下载它
如果[$?-ne 0];然后#如果文件还不可用
rm/tmp/lockfile_$(日期+%F)#删除锁以便在5”内再次尝试下载
fi
完成
fi

能否确认您希望cron任务在文件可用时每天下载一次20+mb的文件,确保它在执行进一步操作之前下载了整个文件,然后在一天的其余时间停止执行?@Aaron实际文件每天为32-35 mb