40 lines
1.1 KiB
Bash
40 lines
1.1 KiB
Bash
#!/bin/bash
|
|
|
|
set -e # Exit on any error
|
|
|
|
# Get the directory of the script
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
# Find node executable
|
|
node=$(which node)
|
|
|
|
# Get database credentials from config
|
|
db_user=$($node -e "console.log(require('${SCRIPT_DIR}/../src/config/database.js').development.connection.user);")
|
|
if [ -z "$db_user" ]; then
|
|
echo "Error: Could not get database user"
|
|
exit 1
|
|
fi
|
|
|
|
db_pass=$($node -e "console.log(require('${SCRIPT_DIR}/../src/config/database.js').development.connection.password);")
|
|
if [ -z "$db_pass" ]; then
|
|
echo "Error: Could not get database password"
|
|
exit 1
|
|
fi
|
|
|
|
db_name=$($node -e "console.log(require('${SCRIPT_DIR}/../src/config/database.js').development.connection.database);")
|
|
if [ -z "$db_name" ]; then
|
|
echo "Error: Could not get database name"
|
|
exit 1
|
|
fi
|
|
|
|
mysql -u"$db_user" -p"$db_pass" "$db_name" <<EOF
|
|
SELECT * FROM messages
|
|
WHERE created_at < DATE_SUB(NOW(), INTERVAL 24 HOUR);
|
|
EOF
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo "Successfully cleaned up expired emails and messages"
|
|
else
|
|
echo "Error occurred while cleaning up expired emails and messages"
|
|
exit 1
|
|
fi |