#!/bin/bash
#
# Cleans up old SMS (older than 30 minutes) to keep /tmp clean
#

SMS_SPOOL_BASE=/tmp/sms

if [ ! -d ${SMS_SPOOL_BASE} ]; then
	exit 0
fi

# get current time
c_time=$(date +%s)

for file in $(find ${SMS_SPOOL_BASE} -type f); do
	# get file create time
	f_time=$(date -r ${file} +%s)

	# calculate time at which file is considered old (30 minutes)
	let o_time="${f_time}+(60*30)"

	# if the file is too old, delete it
	if [ "${c_time}" -ge "${o_time}" ]; then
		rm -rf ${file}
	fi
done
