0

I need some help here, I'm not a expert with shell scripting but I am trying to do a script where I need to take the Epoch number followed by the date, but for with the all hours of the day with a interval of 15 minutes. The result will be something like this

1376708400|2013-08-17 00:00:00
1376709300|2013-08-17 00:15:00
1376710200|2013-08-17 00:30:00

In the total I'll have 96 lines, my biggest doubt right now is how i can increment (or sum) the minutes by 15 minutes, i have tried this

My full script right now is this (I know is terrible, but I'm not a truly programmer. I'm learning)

i=96

_incrementatime='+15 minutos'

count=1

_Date=$(`date "2013-08-29 00:00:00"`)
_dataEmSeg = `date -d "2013-08-29 00:00:00" +%s`

while  test $i -ne 0

do
    _VarData=$(`date --date="$_incrementatime*count"`)

    _exprt=$(expr `$_Date+$_VarData`)
    echo "$_dataEmSeg  e  $_exprt    "

    i=$((i-1))
    count=$((count+1))
done

If someone can give me the directions to resolve this I`ll be very thankfull.

1
  • Is this bash or another shell? Looks like bash but you have not said. I also assume you are running some kind of *nix system.
    – terdon
    Sep 4, 2013 at 21:15

2 Answers 2

0

If you are using GNU date, it can almost do everything itself:

#!/usr/bin/env bash

_Date=$(date -d "2013-08-29 00:00:00");
for ((i=0; i<96; i++)); do 
    echo $(date -d "$_Date" +%s)"|"$(date -d "$_Date" +"%F %T")
    _Date=$(date -d "$_Date +15 minutes")
done

There were various small errors and unnecessary steps in your script which I removed or corrected.

0

You didn't mention the system you're on, but there's dseq(1) from my dateutils collection to produce a sequence of dates:

$ dseq '2013-08-17 00:00:00' +15m '2013-08-18 00:00:00' -f '%s|%F %T'
1376697600|2013-08-17 00:00:00
1376698500|2013-08-17 00:15:00
...

The first 3 arguments denote the starting and end point of the sequence, the middle one being the increment (just like seq(1) really). The -f switch allows you to specify the output format, and takes format specifiers similar to those in GNU date.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .