Accel-ppp and ABillS session synchronization script

A simple session synchronization script between Accel-ppp and ABillS.

I didn’t notice the desynchronization of client sessions at 5k ipoe clients, however, some acquaintances had it, so I’ll just leave this simple script for you here, the author of the script Nikolay Onyshchenko (@KROLb):

#!/bin/bash
/usr/bin/accel-cmd show sessions ip order ip | sed 's/ //g; /^[[:blank:]]*$/ d; /-----------------/ d; /ip/ d' | sort > /tmp/accel-ips
/usr/bin/dos2unix /tmp/accel-ips

#/usr/bin/mysql --batch -N -u root abills -e "select INET_NTOA(framed_ip_address) from internet_online" | sort > /tmp/abills-ips
/usr/bin/mysql --batch -N -u root abills -e "select INET_NTOA(framed_ip_address) from internet_online where status='3'" | sort > /tmp/abills-ips
/usr/bin/dos2unix /tmp/abills-ips

for i in `cat /tmp/accel-ips`
do
  count=`cat /tmp/abills-ips | /bin/grep $i | wc -l`
  #echo "Different in sessions: $count"
  if [[ $count -lt 1 ]]; then
    #/usr/bin/accel-cmd terminate ip $i hard
    /usr/bin/accel-cmd terminate ip $i soft
    #sleep 1
    echo "Soft terminate for $i"
  fi
done

Don’t forget to install dos2unix:

apt install dos2unix

If billing and accel-ppp are on different servers, then you can transfer files with a list of sessions, for example, via ssh(scp), or connect to the database remotely, for example, I changed the script to this form:

#!/bin/bash
/usr/bin/accel-cmd -P pass -H192.168.5.5 show sessions ip order ip | sed 's/ //g; /^[[:blank:]]*$/ d; /-----------------/ d; /ip/ d' | sort > /tmp/accel-ips
/usr/bin/dos2unix /tmp/accel-ips
 
#/usr/bin/mysql --batch -N -u USERNAME -pPASSWORDHERE -h 192.168.5.10 -D abills -e "select INET_NTOA(framed_ip_address) from internet_online where status='3'" | sort > /tmp/abills-ips
/usr/bin/mysql --batch -N -u USERNAME -pPASSWORDHERE -h 192.168.5.10 -D abills -e "select INET_NTOA(framed_ip_address) from internet_online" | sort > /tmp/abills-ips
/usr/bin/dos2unix /tmp/abills-ips
 
for i in `cat /tmp/accel-ips`
do
  count=`cat /tmp/abills-ips | /bin/grep $i | wc -l`
  #echo "Different in sessions: $count"
  if [[ $count -lt 1 ]]; then
    #/usr/bin/accel-cmd terminate ip $i hard
    #/usr/bin/accel-cmd terminate ip $i soft
    echo $i >> /tmp/test.txt
#sleep 1
    echo "Soft terminate for $i"
  fi
done

Also in the script, I commented out the termination of sessions and indicated the recording of non-existent sessions in the /tmp/test.txt file, it is advisable to do this at the first start to check the script, for example, if the script cannot connect to mysql, then in this case it will start to end all sessions as the file /tmp/abills-ips will be empty.

See also my article:
Accel-ppp session termination script

Leave a comment

Leave a Reply