#!/bin/bash
#first arg is device id, second is output file
mysql -h mysql5host.bath.ac.uk -u eliten -p PROJenliten -e "select 'temperature', temperature, UNIX_TIMESTAMP(timestamp) - mod(UNIX_TIMESTAMP(timestamp),60)+3600, sensor from temperature where device = $1 and timestamp >= '2013-08-05' and timestamp < '2013-08-12' union all select 'humidity', humidity, UNIX_TIMESTAMP(timestamp) - mod(UNIX_TIMESTAMP(timestamp),60)+3600, sensor from humidity where device = $1 and timestamp >= '2013-08-05' and timestamp < '2013-08-12' union all select 'light', value, UNIX_TIMESTAMP(timestamp) - mod(UNIX_TIMESTAMP(timestamp),60)+3600, sensor from light where device = $1 and timestamp >= '2013-08-05' and timestamp < '2013-08-12' union all select 'pir', event, UNIX_TIMESTAMP(timestamp) - mod(UNIX_TIMESTAMP(timestamp),60)+3600, sensor from pir where device = $1 and timestamp >= '2013-08-05' and timestamp < '2013-08-12';" > $2 
