Created
February 17, 2021 15:36
-
-
Save PVince81/300f03d277a1eb8c876a27b5ddae932e to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/bash | |
NC_URL="https://nchost" | |
USERS=(alice bob charles dave) | |
PASSWORD=passwordcomeshere | |
C=1 | |
SPECIFIC_ROOM="$1" | |
while true; | |
do | |
USER=${USERS[$RANDOM % ${#USERS[@]} ]} | |
# get all non-readonly rooms | |
if test -z "$SPECIFIC_ROOM"; then | |
ROOMS=($(curl "${NC_URL}/ocs/v2.php/apps/spreed/api/v3/room?format=json" \ | |
-X GET \ | |
-u "$USER:$PASSWORD" \ | |
-H 'OCS-APIRequest: true' \ | |
-s | jq -r ".ocs.data[] | select(.readOnly==0).token" | |
)) | |
if test ${#ROOMS[@]} -eq 0; then | |
continue | |
fi | |
ROOM=${ROOMS[$RANDOM % ${#ROOMS[@]}]} | |
else | |
ROOM="$SPECIFIC_ROOM" | |
fi | |
MESSAGE="Counter is $C" | |
C=$((C + 1)) | |
echo User \"$USER\" posting \"$MESSAGE\" to room \"$ROOM\" | |
DATA='{"message":"'$MESSAGE'"}' | |
curl "${NC_URL}/ocs/v2.php/apps/spreed/api/v1/chat/$ROOM" \ | |
-X POST \ | |
-u "$USER:$PASSWORD" \ | |
-H 'Content-Type: application/json;charset=UTF-8' \ | |
-H 'OCS-APIRequest: true' \ | |
--data-binary "$DATA" \ | |
-s > /dev/null || echo "Failed" >&2 | |
sleep $(($RANDOM % 3)) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment