MikeDave888
Programmer
Hello everyone,
I hope you can help me with the issue I am having. I tried to run a Crontab job on odd/even weeks but couldn't get it to work. Below has the detail. I'd greatly appreciate any feedback that you can provide. Thank you...
# The job ran and the script got executed.
15 17 * * 1 test 0 -eq 0 && /path/script_name.sh
# But when I tried to run the script on even weeks, the script didn't get executed.
15 17 * * 1 test $(echo $(($(date +%V) % 2))) -eq 0 && /path/script_name.sh
# The job ran and the script got executed.
15 17 * * 1 test 1 -eq 1 && /path/script_name.sh
# But when I tried to run the script on odd weeks, the script didn't get executed.
15 17 * * 1 test $(echo $(($(date +%V) % 2))) -eq 1 && /path/script_name.sh
I also tested the following and they work but when using them within the Crontab job they seem not to be working.
oracle@testdb:/home/oracle> if test $(echo $(($(date +%V) % 2))) -eq 0; then echo "0"; else echo "1"; fi
0
oracle@testdb:/home/oracle> if test $(echo $(($(date +%V -d '2020/01/27') % 2))) -eq 0; then echo "0"; else echo "1"; fi
1
oracle@testdb:/home/oracle> if test $(echo $(($(date +%V -d '2020/02/03') % 2))) -eq 0; then echo "0"; else echo "1"; fi
0
Thanks and Regards,
Mike
I hope you can help me with the issue I am having. I tried to run a Crontab job on odd/even weeks but couldn't get it to work. Below has the detail. I'd greatly appreciate any feedback that you can provide. Thank you...
# The job ran and the script got executed.
15 17 * * 1 test 0 -eq 0 && /path/script_name.sh
# But when I tried to run the script on even weeks, the script didn't get executed.
15 17 * * 1 test $(echo $(($(date +%V) % 2))) -eq 0 && /path/script_name.sh
# The job ran and the script got executed.
15 17 * * 1 test 1 -eq 1 && /path/script_name.sh
# But when I tried to run the script on odd weeks, the script didn't get executed.
15 17 * * 1 test $(echo $(($(date +%V) % 2))) -eq 1 && /path/script_name.sh
I also tested the following and they work but when using them within the Crontab job they seem not to be working.
oracle@testdb:/home/oracle> if test $(echo $(($(date +%V) % 2))) -eq 0; then echo "0"; else echo "1"; fi
0
oracle@testdb:/home/oracle> if test $(echo $(($(date +%V -d '2020/01/27') % 2))) -eq 0; then echo "0"; else echo "1"; fi
1
oracle@testdb:/home/oracle> if test $(echo $(($(date +%V -d '2020/02/03') % 2))) -eq 0; then echo "0"; else echo "1"; fi
0
Thanks and Regards,
Mike