Scripting Tips
Issuing Globus Commands in a Script
In order to issue Globus CLI commands from within a script, you will need to be authenticated both with Globus and for any endpoints you will be using. When you log in to Globus, you are given tokens for both your active session and for restoring your access when the active session expires. As long as you use the Globus CLI within six months, the token for restoring access remains valid and you won't have to log in again.
However, endpoint activations expire much more quickly, and you will probably need to re-authenticate frequently to keep using an endpoint. Endpoint activation is an interactive process and must be performed outside of your script. You may want to include checks at the beginning of your script to determine if all necessary endpoints are currently active. The following command will return 0 if the identified endpoint is active and will otherwise return non-zero:
Remembering Endpoints
Any script that transfers files using the Globus CLI
will need to know the IDs of the endpoints that are involved in the transfer.
Endpoint IDs generally do not change over time,
so it is easy to capture their IDs using globus endpoint search
and assign those IDs to variables in your script,
much as was done in the shell when discussing transfer commands.
Disabling Email Notifications
By default, each Globus transfer operation will
send a completion email to the user who executed the command.
Since this may be undesirable when many transfers are executed from within a script,
you may want to disable the notifications using the --notify off
option of
the CLI's globus transfer
command.
In addition to turning notifications off, you can also limit them based on type.
The arguments succeeded
, failed
and inactive
can be used instead to indicate the only types of notifications to send by email.
The following example will send emails for any transactions that do not succeed.
The following pages provide details about executing specific Globus CLI commands from within a script and present a sample of a complete script that issues CLI commands.