I am reading dates 'VARCHAR(14)'
from an oracle table with a sql query in BASH, into a variable. I want to compare that date (eg. 20140611120520
) with the system date. If the variable date is 15 minutes or older than the system date I need to kick off another procedure.
This is my query:
Get_einlag_time=`sqlplus ips_osmr/ips_osmr << eof | awk ' $1 == "This" { print $2 } '
select 'This ' || DZ_EINLAG
from LAG_SPI
where C_STATUS like '%E%' ;
eof
`
$Get_einlag_time
- may result in more than one date seperated by a space (eg. 20140411141231 20140605075650
)
I then read the dates one by one fom this variable with a For GET_TIME in $Get_einlag_time
loop, comparing them with the system date.
Now I have this date value in $GET_TIME
but I cannot do a date comparison as I get 'invalid date' from this variable.
This was my latest try in convertion before I gave up to ask for expert advice :-)
echo "time read from Get_einlag_time is $GET_TIME"
EINLAG_TIME=$(date +%Y%m%d -d "$GET_TIME")
EINLAG_CHK=$(date -d "$EINLAG_TIME+15 Minutes" +%Y%m%d%H%M%S)
EINLAG_SEC=$(date -d "$EINLAG_TIME" +%s)
COMPARE_TIME=$(date +%Y%m%d%H%M%S)
COMP_SEC=$(date +%s)
The $EINLAG_SEC
converted %s gives me an extremely huge and unlikely value.
The 'this' and Print$2 is used in my awk to get rid of the headers etc when the oracle query returns so have clean data. – Wouter Jun 06 '14 at 09:48