-
Notifications
You must be signed in to change notification settings - Fork 88
Bulk Processing
!# Bulk Processing
- Introduction
- Python Regular Expressions
- GAM Configuration
- Meta Commands and File Redirection
- Definitions
- Batch files
- CSV files
- CSV files with redirection and select
- Automatic batch processing
Batch and CSV file processing can improve performance by executing Gam commands in parallel.
The variables num_threads
, num_tbatch_threads
and auto_batch_min
in gam.cfg
control parallelism.
-
Command data from Google Docs/Sheets/Storage
gdoc <UserGoogleDoc>
andgsheet <UserGoogleSheet>
There are two types of batch processing, one that uses processes and one that uses threads. Using processes is higher performance but gam csv
commands are not supported.
-
gam batch
- gam commands are run as processes, gam csv commands are not allowed in the batch file -
gam tbatch
- gam commands are run as threads, gam csv commands are allowed in the batch file
gam batch <FileName>|-|(gdoc <UserGoogleDoc>) [charset <Charset>] [showcmds [<Boolean>]]
gam tbatch <FileName>|-|(gdoc <UserGoogleDoc>) [charset <Charset>] [showcmds [<Boolean>]]
-
<FileName>
- A flat file containing Gam commands -
-
- Gam commands coming from stdin -
gdoc <UserGoogleDoc>
- A Google Doc containing Gam commands -
showcmds
- Writetimestamp,command number/number of commands,command
to stderr when each command starts; writetimestamp, command number/numberof commands,complete
to stderr when command completes
Batch files can contain the following types of lines:
- Blank lines - Ignored
- # Comment line - Ignored
- gam <GAMArgumentList> - Execute a GAM command
- commit-batch
- GAM waits for all running GAM commands to complete
- GAM continues
- commit-batch <String>
- GAM waits for all running GAM commands to complete
- GAM prints <String> and waits for the user to press any key
- GAM continues
- print <String> - Print <String> on stderr
Tbatch files can also contain the following line:
- execute <Program> <ArgumentList> - Execute an arbitrary command; use the full path to specify <Program>
- You need to create accounts for your new students and assign them to groups based on their graduation year.
- You have a CSV file NewStudents.csv with columns: Email,First,Last,GradYear,Password
- You have a batch file NewStudents.bat containing these commands:
gam csv NewStudents.csv gam create user ~Email firstname ~First lastname ~Last org "/Students/~~GradYear~~" password ~Password
commit-batch
gam update group seniors sync members ou /Students/2020
gam update group juniors sync members ou /Students/2021
gam update group sophomores sync members ou /Students/2022
gam update group highschool sync members ous "'/Students/2020','/Students/2021','/Students/2022'"
- Execute the batch file
gam redirect stdout ./NewStudents.out redirect stderr ./NewStudents.err tbatch NewStudents.bat showcmds
gam csv <FileName>|-|(gsheet <UserGoogleSheet>)|(gdoc <UserGoogleDoc>) [charset <Charset>] [warnifnodata]
[columndelimiter <Character>] [quotechar <Character>] [fields <FieldNameList>]
(matchfield|skipfield <FieldName> <RegularExpression>)* [showcmds [<Boolean>]]
[maxrows <Integer>]
gam <GAMArgumentList>
gam loop <FileName>|-|(gsheet <UserGoogleSheet>)|(gdoc <UserGoogleDoc>) [charset <Charset>] [warnifnodata]
[columndelimiter <Character>] [quotechar <Character>] [fields <FieldNameList>]
(matchfield|skipfield <FieldName> <RegularExpression>)* [showcmds [<Boolean>]]
[maxrows <Integer>]
gam <GAMArgumentList>
-
gam csv
- Use parallel processing -
gam loop
- Use serial processing -
<FileName>
- A CSV file and the one or more columns that contain data -
-
- The one or more columns that contain data from stdin -
gsheet <UserGoogleSheet>
- A Google Sheet and the one or more columns that contain data -
gdoc <UserGoogleDoc>
- A Google Doc and the one or more columns that contain data -
columndelimiter <Character>
- Columns are separated by<Character>
; if not specified, the value ofcsv_input_column_delimiter
fromgam.cfg
will be used -
quotechar <Character>
- The column quote characer is<Character>
; if not specified, the value ofcsv_input_quote_char
fromgam.cfg
will be used -
fields <FieldNameList>
- The column headings of a CSV file that does not contain column headings. -
(matchfield|skipfield <FieldName> <RegularExpression>)*
- The criteria to select rows from the CSV file; can be used multiple times; if not specified, all rows are selected -
showcmds
- Writetimestamp,command number/number of commands,command
to stderr when each command starts; writetimestamp, command number/numberof commands,complete
to stderr when command completes -
maxrows <Integer>
- Limit the number of filtered rows processed from the CSV file/Google Sheet.-
maxrows 0
- All rows are processed, this is the default -
maxrows N
- N filtered rows are processed
-
You can make substitutions in <GAMArgumentList>
with values from the CSV file.
- Reference the field xxx with
~xxx
if the argument contains no other text - Reference the field xxx with
~~xxx~~
if the argument contains other text - An argument containing exactly
~xxx
is replaced by the value of field xxx - An argument containing instances of
~~xxx~~
has~~xxx~~
replaced by the value of field xxx - An argument containing instances of
~~xxx~!~pattern~!~replacement~~
has~~xxx~!~pattern~!~replacement~~
replaced by re.sub(pattern, replacement, value of field xxx) See: https://docs.python.org/3/library/re.html
- You need to update the work addresses of a set of users
- You want a note field that shows their email address as name AT domain.com
- You have a CSV file Users.csv with columns: primaryEmail,Street,City,State,ZIP
gam csv Users.csv gam update user ~primaryEmail address type work unstructured "~~Street~~, ~~City~~, ~~State~~ ~~ZIP~~" primary note text_plain "~~primaryEmail~!~^(.+)@(.+)$~!~\1 AT \2~~"
- You want to do the above using a Google Sheet
gam csv gsheet <user> <fileID> "<sheetName>" gam update user ~primaryEmail address type work unstructured "~~Street~~, ~~City~~, ~~State~~ ~~ZIP~~" primary note text_plain "~~primaryEmail~!~^(.+)@(.+)$~!~\1 AT \2~~"
You should use the multiprocess
option on any redirected files: csv
, stdout
, stderr
.
gam redirect csv ./filelistperms.csv multiprocess csv Users.csv gam user ~primaryEmail print filelist fields id,title,permissions,owners.emailaddress
If you want to select a gam.cfg
section for the command, you can select the section at the outer gam
and save it
or select the section at the inner gam
.
gam select <Section> save redirect csv ./filelistperms.csv multiprocess csv Users.csv gam user ~primaryEmail print filelist fields id,title,permissions,owners.emailaddress
gam redirect csv ./filelistperms.csv multiprocess csv Users.csv gam select <Section> user ~primaryEmail print filelist fields id,title,permissions,owners.emailaddress
You can enable automatic batch (parallel) processing when issuing commands of the form gam <UserTypeEntity> ...
.
In the following example, if the number of users in group [email protected] exceeds 1, then the print filelist
command will be processed in parallel.
gam config auto_batch_min 1 redirect csv ./filelistperms.csv multiprocess group [email protected] print filelist fields id,title,permissions,owners.emailaddress
With automatic batch processing, you should use the multiprocess
option on any redirected files: csv
, stdout
, stderr
.
If you want to select a gam.cfg
section for the command, you must select and save it for it to be processed correctly.
gam select <Section> save config auto_batch_min 1 redirect csv ./filelistperms.csv multiprocess group [email protected] print filelist fields id,title,permissions,owners.emailaddress
Need more help? Ask on the GAM Discussion Group
Update History
Installation
- How to Install GAM7
- How to Update Advanced GAM to GAM7
- How to Update GAM7
- How to Upgrade from Legacy GAM
- Install GAM as Python Library
- GAM7 on Chrome OS Devices
- GAM7 on Android Devices
- Google Network Addresses
- HTTPS Proxy
- SSL Root CA Certificates
- How to Uninstall GAM7
Configuration
- Authorization
- GAM Configuration
- Running GAM7 securely on a Google Compute Engine
- Using GAM7 with a delegated admin service account
- Using GAM7 with a YubiKey
Notes and Information
- Upgrade Benefits
- Questions? Visit the GAM Discussion Forum
- Scripts
- Other Resources
- Drive REST API v3
- BNF Syntax
- GAM Return Codes
- Python Regular Expressions
- Rclone
Definitions
Command Processing
- Bulk Processing
- Command Line Parsing
- Command Logging and Progress
- Command data from Google Docs/Sheets/Storage
- CSV Special Characters
- CSV Input Filtering
- CSV Output Filtering
- Meta Commands and File Redirection
- Permission matches
- Tag Replace
- Todrive
Collections
Client Access
- Addresses
- Administrators
- Alert Center
- Aliases
- Calendars
- Calendars - Access
- Calendars - Events
- Chrome Auto Update Expiration Counts
- Chrome Browser Cloud Management
- Chrome Device Needs Attention Counts
- Chrome Installed Apps
- Chrome Policies
- Chrome Printers
- Chrome Version Counts
- Chrome Version History
- ChromeOS Devices
- Classroom - Courses
- Classroom - Guardians
- Classroom - Invitations
- Classroom - Membership
- Cloud Channel
- Cloud Identity Devices
- Cloud Identity Groups
- Cloud Identity Groups - Membership
- Cloud Identity Policies
- Cloud Storage
- Context Aware Access Levels
- Customer
- Domains
- Domains - Verification
- Domain People - Contacts & Profiles
- Domain Shared Contacts - Global Address List
- Email Audit Monitor
- Find File Owner
- Google Data Transfers
- Groups
- Groups - Membership
- Inbound SSO
- Licenses
- Mobile Devices
- Organizational Units
- Reports
- Reseller
- Resources
- Send Email
- Schemas
- Shared Drives
- Sites
- Users
- Unmanaged Accounts
- Users - Signout and Turn off 2-Step Verification
- Vault - Takeout
- Version and Help
Special Service Account Access
Service Account Access
- Users - Analytics Admin
- Users - Application Specific Passwords
- Users - Backup Verification Codes
- Users - Calendars
- Users - Calendars - Access
- Users - Calendars - Events
- Users - Chat
- Users - Classification Labels
- Users - Classroom - Profile
- Users - Deprovision
- Users - Contacts
- Users - Contacts - Delegates
- Users - Drive - File Selection
- Users - Drive - Activity/Settings
- Users - Drive - Cleanup
- Users - Drive - Comments
- Users - Drive - Copy/Move
- Users - Drive - Files-Display
- Users - Drive - Files-Manage
- Users - Drive - Orphans
- Users - Drive - Ownership
- Users - Drive - Permissions
- Users - Drive - Query
- Users - Drive - Revisions
- Users - Drive - Shortcuts
- Users - Drive - Transfer
- Users - Forms
- Users - Gmail - Client Side Encryption
- Users - Gmail - Delegates
- Users - Gmail - Filters
- Users - Gmail - Forwarding
- Users - Gmail - Labels
- Users - Gmail - Messages/Threads
- Users - Gmail - Profile
- Users - Gmail - S/MIME
- Users - Gmail - SendAs/Signature/Vacation
- Users - Gmail - Settings
- Users - Group Membership
- Users - Keep
- Users - Looker Studio
- Users - Meet
- Users - Classroom - Profile
- Users - People - Contacts & Profiles
- Users - Photo
- Users - Profile Sharing
- Users - Shared Drives
- Users - Spreadsheets
- Users - Tasks
- Users - Tokens
- Users - YouTube