Not so necessary for just seven dates as they could each be declared individually, but for any greater date range would be useful, as converting to epoch seconds means that the two dates can be compared as to which is greater, with later dates obviously being greater than....
#!/bin/sh
#GET CURRENT DATE IN EPOCH SECONDS#
export todaysdate=`date +%s`
#7DAYS AGO IS -604800 SECONDS#
sevendaysago="$(( $todaysdate - 604800 ))"
#QUERY DATABASE TO GET MERCHANT ID ANF LOOP THROUGH EACH#
merchant=`
mysql -u username --password=password << eof
use databasename;
SELECT merchantid FROM tablename;
eof`
for ARG1 in $merchant
do
#QUERY DATABASE TO GET DATE DATA WAS ALTERED FOR EACH MERCHANT#
date=`
mysql -u username --password=password << eof
use database;
SELECT lastUpdated FROM tablename WHERE merchantid='$ARG1';
eof`
for ARG2 in $date
do
#IGNORE COLUMN NAME IN RETURNED RESULT#
if [ "$ARG2" != "lastUpdated" ]; then
#CONVERT DATE TO EPOCH SECONDS#
export recordeddate=`date -d "$ARG2" +%s`
#COMPARE RECORDED DATE TO DATE SEVEN DAYS AGO#
if [ $recordeddate -gt $sevendaysago ]; then
#DO WHATEVER#
echo $ARG1 data changed in the last seven days on $ARG2
fi
fi
done
done
Linux Questions
No comments:
Post a Comment