1850467 Members
2413 Online
104054 Solutions
New Discussion

Script question

 
SOLVED
Go to solution
Jeff Picton
Regular Advisor

Script question

Hi

Can anybody tell me how to determine from a day of the week output, how I may classify this as an A cycle, B cycle or C cycle assuming each cycle is of duration 7 days ?
3 REPLIES 3
Massimo Bianchi
Honored Contributor
Solution

Re: Script question

date +%j will tell you the day number in the year
% is the modulus operator

#!/sbin/sh
TODAY=$(date +%j)
let CYCLE=$TODAY%21
case $CYCLE in
0|1|2|3|4|5|6) echo "Cycle A";;
7|8|9|10|11|12|13) echo "Cycle B";;
14|15|16|17|18|19|20) echo "Cycle C";;
esac;

The only problem in on year-change, since the count is resetted to 0.

But maybe you can cope with it, or write additional code to keep track of the last cycle and change the script itself.

Massimo



Tim Adamson_1
Honored Contributor

Re: Script question

Hi Jeff,

Could you elaborate a bit more on what you are trying to achieve. I don't fully understand.


Cheers,


Tim
Yesterday is history, tomorrow is a mystery, today is a gift. That's why it's called the present.
Jeff Picton
Regular Advisor

Re: Script question

Hi Tim

I have a script caljd which calculates the julian day :-

caljd.sh -D -p 1
02

so day_of_week='caljd.sh -D -p 1' gives 02.

From this I need to use a case statement similar to that of Massimo to determine if this is cycle A B or C.

Jeff