#!/bin/bash echo -ne "[client]\nhost=${HOST}\nport=${PORT}\nuser=${MYSQL_USER}\npassword=${MYSQL_PASSWORD}\n" > /etc/my.cnf create_time=$(mysql --defaults-extra-file=/etc/my.cnf -e "SELECT NOW() - INTERVAL '$REMAIN_DAYS' DAY"|egrep '[0-9]{4}') if [ -z "$create_time" ]; then echo "Failed to retrieve create_time. Exiting." exit 1 fi echo "Deleting records older than: $create_time" mysql --defaults-extra-file=/etc/my.cnf -e "delete * from question.code_run where create_time <'${create_time}'"