Forum

Ask, reply and learn. Join the community of Akaunting.

New Discussion

Run a Crontab job on odd/even weeks

Mike L.   ( User )

Commented 4 years ago

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

Mike L.   ( User )

Commented 4 years ago

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

Please login or register to leave a response.

Showing 1 to 2 of 2 discussions