AlexeyKa
AlexeyKa

Reputation: 558

How start ejabberdctl from bash script properly?

I need to register many thousands of users in ejabberd from csv file. For this, I wrote a simple script.

#!/bin/sh
OLDIFS=$IFS
IFS=','
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read username domain pass p1 p2 p3 p4
do
    echo "ejabberdctl register $username $domain $pass"
    ejabberdctl register $username $domain $pass
done < users.csv
IFS=$OLDIFS

But in the end, the answer is: Error: cannot_register If I just run the line copied from the output, everything is ok. The user is created normally.

Upvotes: 0

Views: 102

Answers (1)

Badlop
Badlop

Reputation: 4120

This is just a little trick for later: once you get your loop working, if you consider ejabberdctl is too slow, you can try using the ReST API. That should be a lot faster when doing many requests.

Configure temporarily something like this (remember to remove this when you finished):

listen:
  -
    port: 5280
    module: ejabberd_http
    tls: false 
    request_handlers:
      /api: mod_http_api

api_permissions:
  "console commands":
    from:
      - ejabberd_ctl
      - mod_http_api
    who: all
    what: "*"

modules:
  mod_http_api: {}

Then execute this in a shell to register an account:

curl 'localhost:5280/api/register?user=user2&host=localhost&password=somepass123'

Upvotes: 1

Related Questions