-
Notifications
You must be signed in to change notification settings - Fork 3
Other Server Modifications
If you want to set an expiration date for users who have been logged in, follow the steps below: First, ensure that cron is installed on your server:
sudo apt install cronThen, create a new script called delete_expired_logins.sh inside a folder (e.g., server-scripts or within database configurations). Here's the content of the script:
#!/bin/bash
# Variables for PostgreSQL credentials
PG_USER="ermis_admin"
PG_PASSWORD="ermis_password"
PG_HOST="localhost"
PG_PORT="5432"
PG_DB="ermis_database"
# SQL query to delete rows from table `user_ips` older than one month
SQL_QUERY="DELETE FROM user_devices WHERE logged_in_at < NOW() - INTERVAL '1 month';"
# Run the query using psql
export PGPASSWORD=$PG_PASSWORD
psql -U $PG_USER -d $PG_DB -h $PG_HOST -p $PG_PORT -c "$SQL_QUERY"After creating the script, you need to make it executable. Run the following command:
chmod +x /path/to/server-scripts/delete_expired_logins.shNow, schedule the script to run automatically using cron. To run the script every day at midnight, open the crontab for editing:
crontab -eThen, add the following line to schedule the script:
0 0 * * * /path/to/server-scripts/delete_expired_logins.shThis cron job will execute the script every day at midnight, which will, in turn, run the PostgreSQL query to delete rows from the user_ips table where the logged_in_at timestamp is older than one month.
To verify that the cron job has been added, you can list the current cron jobs by running:
crontab -lYou should see the job listed, like this:
0 0 * * * /path/to/server-scripts/delete_expired_logins.shWhich ensures the cron job is set up and will run as expected.
"Arguing that you don’t care about the right to privacy because you have nothing to hide is no different than saying you don’t care about free speech because you have nothing to say"
— Dr. Edward Snowden