Last active
May 28, 2018 21:40
-
-
Save dlopes7/5417c65d7f770023aa8cd27b2bf1ae7a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
APPD_CONTROLLER=http://controller:8090 | |
APPD_USER=admin | |
APPD_ACCOUNT=customer1 | |
APPD_PASSWORD=password | |
# Login to the controller for restui calls | |
curl -s --user $APPD_USER@$APPD_ACCOUNT:$APPD_PASSWORD --cookie-jar cookies.jar $APPD_CONTROLLER/auth?action=login | |
# Gets a list of apps | |
echo "Getting all apps" | |
APPS=($(curl -s --user $APPD_USER@$APPD_ACCOUNT:$APPD_PASSWORD $APPD_CONTROLLER/controller/rest/applications?output=json \ | |
| grep "\"id\"" | awk -F ':' '{print $2}')) | |
for app in "${APPS[@]}" | |
do | |
echo "Looking for sessions for app ID $app" | |
URL="controller/restui/btdiscovery/sessions/$app" | |
SESSIONS=($(curl -s --user $APPD_USER@$APPD_ACCOUNT:$APPD_PASSWORD \ | |
--cookie cookies.jar \ | |
-H "accept: application/json, text/plain, */*" \ | |
-H "X-CSRF-TOKEN: $(grep X-CSRF-TOKEN cookies.jar | awk '{print $7}')" \ | |
-H "Content-Type: application/json" $APPD_CONTROLLER/$URL \ | |
| grep "^ \"sessionId\"" | awk -F ':' '{print $2}' | cut -d \" -f2)) | |
for session in "${SESSIONS[@]}" | |
do | |
echo "Found session $session for app ID $app, deleting..." | |
URL="controller/restui/btdiscovery/sessions/$session/close" | |
curl -s --user $APPD_USER@$APPD_ACCOUNT:$APPD_PASSWORD \ | |
--cookie cookies.jar \ | |
-H "accept: application/json, text/plain, */*" \ | |
-H "X-CSRF-TOKEN: $(grep X-CSRF-TOKEN cookies.jar | awk '{print $7}')" \ | |
-H "Content-Type: application/json" \ | |
$APPD_CONTROLLER/$URL | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment