-
Notifications
You must be signed in to change notification settings - Fork 473
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
- Process Google Sheet commands and save results
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
- sleep <Integer> - Batch processing will suspend for <Integer> seconds before the next command line is processed
- To be effective, this should immediately follow commit-batch
- print <String> - Print <String> on stderr
- set <KeywordString> <ValueString>
- Subsequent lines will have %<KeywordString>% replaced with <ValueString>
- clear <KeywordString>
- Subsequent lines will not be scanned for %<KeywordString>%
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>] [noescapechar <Boolean>] [quotechar <Character>] [fields <FieldNameList>]
(matchfield|skipfield <FieldName> <RegularExpression>)* [showcmds [<Boolean>]]
[skiprows <Integer>] [maxrows <Integer>]
gam <GAMArgumentList>
gam loop <FileName>|-|(gsheet <UserGoogleSheet>)|(gdoc <UserGoogleDoc>) [charset <Charset>] [warnifnodata]
[columndelimiter <Character>] [noescapechar <Boolean>] [quotechar <Character>] [fields <FieldNameList>]
(matchfield|skipfield <FieldName> <RegularExpression>)* [showcmds [<Boolean>]]
[skiprows <Integer>] [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 -
noescapechar <Boolean>
- Should\
be ignored as an escape character; if not specified, the value ofcsv_input_no_escape_char
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 -
skiprows <Integer>
- Skip filtered rows from the CSV file/Google Sheet.-
skiprows 0
- All rows are processed, this is the default -
skiprows N
- The first N filtered rows are skipped
-
-
maxrows <Integer>
- Limit the number of filtered rows processed from the CSV file/Google Sheet after any skipped rows.-
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
If an argument is specifying a file path and it starts with a ~
, e.g., targetfolder "~/Documents/GamWork"
, GAM will flag it as an error:
ERROR: Header "/Documents/GamWork/" not found in CSV headers of "Owner,id,title".
Put a space in front of the ~
: targetfolder " ~/Documents/GamWork"
to avoid the error.
- 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,name,mimetype,basicpermissions
gam redirect csv - multiprocess todrive csv Users.csv gam user "~primaryEmail" print filelist fields id,name,mimetype,basicpermissions
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,name,mimetype,basicpermissions
gam redirect csv ./filelistperms.csv multiprocess csv Users.csv gam select <Section> user "~primaryEmail" print filelist fields id,name,mimetype,basicpermissions
gam select <Section> save redirect csv - multiprocess todrive csv Users.csv gam user "~primaryEmail" print filelist fields id,name,mimetype,basicpermissions
gam redirect csv - multiprocess todrive csv Users.csv gam select <Section> user "~primaryEmail" print filelist fields id,name,mimetype,basicpermissions
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 sales@domain.com exceeds 1, then the print filelist
command will be processed in parallel.
gam config auto_batch_min 1 redirect csv ./filelistperms.csv multiprocess group sales@domain.com print filelist fields id,name,mimetype,basicpermissions
gam config auto_batch_min 1 redirect csv - multiprocess todrive group sales@domain.com print filelist fields id,name,mimetype,basicpermissions
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 sales@domain.com print filelist fields id,name,mimetype,basicpermissions
You want to process data from a Google Sheet tab and save the results to another tab in the same sheet. Make a Google sheet with two tabs: Commands, Results; get the File ID and the two tab IDs. Put your command data in the Commands tab.
Run your command, write the results to Results.txt
gam redirect stdout ./Results.txt multiprocess redirect stderr stdout csv gsheet user@domain.com <FileID> id:<CommandsTabID> gam ... Command
Upload Results.txt to the Results tab of the sheet.
gam user user@domain.com update drivefile <FileID> localfile Results.txt retainname gsheet id:<ResultsTabID>
Need more help? Ask on the GAM Discussion Group
Update History
Installation
- How to Install GAM7
- How to Upgrade GAMADV-XTD3 to GAM7
- How to Upgrade Legacy GAM to GAM7
- How to Update GAM7
- Verifying a GAM7 Build is Legitimate and Official
- 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
- GAM with minimal GCP rights
Notes and Information
- Upgrade Benefits
- Questions? Visit the GAM Discussion Forum
- GAM Public Chat Room
- 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 Profile Management
- 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
GAM Tutorials
- Account Auditing
- Calendar Settings
- Chat Bot commands
- Chrome Browser Management
- Chrome Policy Settings
- Context Aware Access levels
- Data Transfers
- Domain Verification
- Google Drive Management
- Group Settings
- Inbound SSO Settings
- Managing Admins
- Managing Classroom
- Managing Custom User Schemas
- Managing Devices
- Managing Organizations
- Managing Product Licenses
- Managing Users, Groups, Aliases, Domains, Mobile and Chrome Devices, and Resource Calendars
- OAuth Authentication Related Commands
- Print Users, Groups, Aliases, Mobile and Chrome OS devices, OUs, Licenses and Reports
- Printers
- Unmanaged Users and Invitations
- User Email Settings
- User Security Settings