Batch Commands
gsm offers a custom “batch” subcommand for many commands that allows you to perform many operations at once (or rather in parallel).
When you use the “batch” subcommand of a normal command, you can use the same flags as the normal command.
However, you will notice that gsm expects you to supply integers for the flag values.
This is because gsm expects you to supply a CSV file with the --path
flag.
The columns in your CSV file need to contain the flag values that you want to use in your batch operation.
You use the columns’ index values as the flag values in your gsm command.
Make sure you set the delimiter according to the format in your CSV file with --delimiter
. The default is “;”.\
In addition to the above, you can also use --<flagName>_ALL
to supply a value that should be applied to ALL lines in your CSV file!
Batch commands are multithreaded. GSM will use 2*“number of CPU cores” by default. You can specify how many threads you want GSM to use by setting the “threads” setting in your config, or be supplying the –batchThreads flag. Note that GSM will never use more than 16 threads.
Example
Normally, to create a user, you would use a command like this:gsm users insert --familyName Doe --givenName Jane --primaryEmail jane@doe.org --password secret123
You could of course create a script and call this command many times for each user you want to create.
However, this will probably be slow, because each time you call gsm, a new HTTP session needs to be established.
Furthermore, gsm’s builtin batch commands automatically use multi-theading and exponential back off and retry if you hit rate limits.
In order to create many users with one call of gsm you can use a command like this:gsm users insert
batch --familyName 1 --givenName 2 --primaryEmail 3 --password 4 --
path ./somefile.csv
where somefile.csv may have the following content:
Jane;Doe;jane@doe.org;jane123
John;Doe;john@doe.org;john123
Jimmy;Doe;jimmy@doe.org;jimmy23
If you want to supply the same password for all users in your CSV:
gsm users insert --familyName 1 --givenName 2 --primaryEmail 3 --
password_ALL "superSecretPasswd13" --path ./somefile.csv
\
Note about headers: Be aware that gsm does NOT use or respect headers in CSV files.
If your CSV file has a header, use --skipHeader
to ignore it (i.e. the first line in your file).
SEE ALSO
- gsm - Command overview
- gsm users insert - Creates a user.
- gsm users insert batch - Batch creates users using a CSV file as input
- examples - See some examples
- scripting examples - Some examples on how to use GSM in scripts