Script to generate connection information for DataSync

0 Likes
By  jwardza

The recommended Best Practices is to remove devices that are no longer being used. And to keep the number of devices down to less than 150 per server. I had an issue where users were testing out different devices then stop using them and not asking us to remove the device. And via the Web console it is very difficult to find devices that are no longer being used.

To fix that I wrote a simple script to query the Mobility Database and write that information to a Web Page. The script is below.

With the upgrade to version 1.2.5 you can have about 750 devices now. Also the schema has changed. I have added the changes to the script to query version 1.2.5.

  1. I created a script in /usr/local/sbin with a name of devices.sh
    #!/bin/sh
    export PGPASSWORD=xxxxxx
    psql mobility -c "select userid,tstamp,devicetype,identifierstring from devices order by userid;" -U datasync_user -H -o /tmp/devices.html
    scp /tmp/devices.html user@hostname.com:/srv/www/htdocs

    Note: If running 1.2.5 use the line below.
    psql mobility -c "SELECT name,tstamp,devicetype,identifierstring FROM devices, users WHERE devices.userid=guid order by name;" -U datasync_user -H -o /tmp/devices.html

    You will need to know the password for the mobility database, you set it when installed Datasync. That password goes in place of xxxxx in the export PGPASSWORD line.

    The last line of the script scp's devices.html to one of our web servers. I used trusted keys between our Linux servers so no password is required.

  • Add the following to your crontab. I run the script every 15 minutes.
    */15 * * * * /usr/local/sbin/devices.sh



If you look at the output you can see all the devices. You can tell which devices are no longer being used by looking at the tstamp (Time Stamp). You can contact the user and ask him to remove his account from that device. And then you can delete the device from Data Sync.

There are other fields you can query. Those are:

userid
deviceid
identifierstring
description
devicetype
configtype
deviceconfig
pingrequest
pingresponseflag
state
statedata
tstamp

Have fun!

Labels:

How To-Best Practice
Comment List
Related
Recommended