Bash reading csv and setting variables headers

137 views
Skip to first unread message

Oleg Brendel

unread,
May 7, 2019, 7:55:15 AM5/7/19
to GAM for G Suite
Hey Folks,

I have successfully made a mini script where an admin can input email values in the terminal and GAM proceeds to deprovision a user according to my logic.

Further I would like to construct a script so that I only need to have a .csv file in that folder path and my logic of several gam commands is applied to every line.

My csv looks like this

email, archive
someuser1@aaa,thisusersarchive@aa
someuser2@aa,thatotherusersarchive
andsoon@aaa, andsoforth@ajkls

Reading here https://github.com/jay0lee/GAM/wiki/BulkOperations#bulk-operations-on-linux helps but I somehow cannot construct the read to have variables whose value changes

example gam logic, this needs to run on each line on the csv:

gam update user $email password somePass email someEmail gal off org /leaver
gam user $email deprovision
gam update alias $email user $archive

In PowerShell with foreach.entry it worked but I need it as .sh script :o

Message has been deleted

Oleg Brendel

unread,
May 7, 2019, 8:34:57 AM5/7/19
to GAM for G Suite

Kevin Melillo ✉

unread,
May 7, 2019, 8:59:28 AM5/7/19
to google-ap...@googlegroups.com
Here is the basic script I use when writing all other scripts for GAM.  With this script you do not need a header row.  The header fields are defined in the while read command.
 
OLDIFS=$IFS
IFS=,
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read email archive
do
  # GAM COMMAND HERE
  # SECOND GAM COMMAND
  # THIRD GAM COMMAND
done < $INPUT
IFS=$OLDIFS

--
You received this message because you are subscribed to the Google Groups "GAM for G Suite" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.
To post to this group, send email to google-ap...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-apps-manager.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/dcc2df97-9f8c-416e-8b69-fa4fc44d9313%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
photo
Kevin Melillo
Electronic Communications Analyst, Information Technology

Phone: 732.465.6609 | Mobile: 732-609-4331

Email: k.me...@ieee.org

445 Hoes Lane Piscataway, NJ 08854
Reply all
Reply to author
Forward
0 new messages