jeudi 26 décembre 2019

If Condition logical error in multiple conditions in loop with cron

I need to run 2 loops in cron which work after every 5 minutes

*/5 * * *  *

loop by cron 1. work in every 5 minutes and check if the file is uploaded or not. ($yesterday mean file with name of backdate)

1st cron-loop work fine to me, 2nd cron-loop I am not able to resolve, 2nd loop have 3 conditions

1. It should work when it found $yesterday.zip

2. It should only work once after $yesterday.zip (because its cron so it work after every 5 minutes when $yesterday.zip found)

3. it should not work 00:00 till $yesterday.zip downloaded

($yesterday file has no fix time to download so i run cron every 5 minutes)  I made this (writing below so you . guys dont think i didnt made effort and didnt say show sampel code, just need a if statement with cron include these 3 conditions)

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

You guys can ignore my above code and simple let me know if statement for such 3 conditons loop

Aucun commentaire:

Enregistrer un commentaire