Quantcast
Channel: Syed Jahanzaib – Personal Blog to Share Knowledge !
Viewing all articles
Browse latest Browse all 408

RM: Delete Expired Users Record

$
0
0

expired.jpg


Following script was made for DMA Radius Manager 4.1.x. It can delete X months old Expired users record from the mysql DB.

Sharing for reference purposes …


#!/bin/sh
#set -x
SQLPASS="MYSQLPASSW0RD"
MONTHSNUMBER="2"
export MYSQL_PWD=$SQLPASS
> /tmp/expired.users.txt
###mysql -uroot -e "use radius; select username from rm_users where expiration BETWEEN '2010-01-01' AND '2019-04-30';" |sort > /tmp/expired.users.txt

# Fetch users who have expired 2 months ago & before, (using expired date), BE CAREFUL WHEN USING THIS

mysql -uroot -e "use radius; select username from rm_users where expiration  /tmp/expired.users.txt
num=0
cat /tmp/expired.users.txt | while read users
do
num=$[$num+1]
USERNAME=`echo $users | awk '{print $1}'`

# Start Deleting account records ...
echo "$USERNAME ---- user record from all relevant tables"
mysql -uroot -e "use radius; DELETE FROM rm_cards WHERE cardnum = '$USERNAME';"
mysql -uroot -e "use radius; DELETE FROM rm_users WHERE username = '$USERNAME';"
mysql -uroot -e "use radius; DELETE FROM rm_changesrv WHERE username = '$USERNAME';"
mysql -uroot -e "use radius; DELETE FROM radcheck WHERE username = '$USERNAME';"
mysql -uroot -e "use radius; DELETE FROM radacct WHERE username = '$USERNAME';"
mysql -uroot -e "use radius; DELETE FROM rm_radacct WHERE username = '$USERNAME';"
done

Jz


Viewing all articles
Browse latest Browse all 408

Trending Articles