0

I would like to write a bash/shell script to loop through 2016-07-27_00:00:00 to 2016-07-29_00:00:00 in 3 hourly interval. My problem is with the hours. I'm a new user and I want to loop through hours.

So that it can look like following:

2016-07-27_00:00:00
2016-07-27_03:00:00
2016-07-27_06:00:00
...and so on.

Can any one kindly help me with that?

Cyrus
  • 84,225
  • 14
  • 89
  • 153
xisan
  • 1
  • 2

1 Answers1

0
for i in 27 28 29; do 
    a=0; 
    while [ $a -lt 24 ]; do 
        printf "2016-07-%s_%02d:00:00\n" $i $a; 
        let a+=3; 
    done; 
done

Something like this. For the three dates, create a string. The day is $i (in printf %s) and the hour is $a. In printf we use %02d to make sure early hours are prefixed with leading 0.

Mko
  • 148
  • 1
  • 6