Reputation: 17
I'm working with a device that needs to receive time instructions formatted on a text file to make backup copies on hour-based timeframes. It has 4 channels so I still need to flag the channels. Format is MMDDhhmmYYYY;C (where MM=month, DD=day, hh=24-hour hour, mm=minute, YYYY=year, C=channel number)
Lets say if I need to specify a 2-hour interval between Jan 25 2016 14:00 and Jan 25 2016 16:00 for channels 1 and 2, I need to put 4 lines on the text file.
012514002016;1
012514002016;2
012515002016;1
012515002016;2
It's OK to do this manually for small queries, but for a full day on 4 channels, I have to write 96 lines. I'm willing to make some script to specify the start date and time, end date and time and which channels to request, then print the output to a text file on the required format, but I don't even know where to start. I saw lots of scripts that can count the interval between dates, but nothing for actually SHOW the interval. The client environment is limited, but at least it's bash 4.0
Upvotes: 0
Views: 79
Reputation: 146073
Well, here is a start. This one only increments hours and doesn't carry hours to days, or minutes to hours, or actually anything.
#!/bin/sh
MM=$1
dd=$2
hh=$3
mm=$4
yyyy=$5
h2=$6
ni=$7
while [ $ni -gt 0 ]; do
for i in 1 2 3 4; do
printf '%02d%02d%02d%02d%04d;%d\n' $MM $dd $hh $mm $yyyy $i
done
hh=$(($hh + $h2))
ni=$(($ni - 1))
done
So to do 12 2-hour increments in a single day:
$ sh interval 01 25 14 00 2016 2 12
Upvotes: 1