![]() |
![]() |
![]() |
![]() |
![]() |
Do you have a google apps domain for education and needs to create accounts for all students? Here is a tutorial with GAM (Google Apps Manager).
Vsebina |
First you must install and run GAM for first activation in your domain. GAM is a command line tool that allows administrators to control their Google Apps domain, manage accounts, groups, and organizations. In this tutorial you will find the scripts used to accredit all the students of a school, about 700 students. They are bash scripts, tested on Linux.
In this example, we imagine that our school is made up of three institutes: "Marconi", "Fermi" and "Volta", for a total of 25 classes, and that the domain name of the school is mfv-school.com. A good choice might be to organize accounts for school / class, creating a group for each class using a unique name, easily recognizable, such as "classe.institute." For students accounts we choose "Last name, First name" <firstname.lastname@domain.tld>, so the accounts are naturally order by last name.
To start, we need a file that describes the organizations and groups and a file with name and surname of students, the Institute and the class. The operations to be performed in sequence will be:
file_group_org.csv (GROUP PARENT ORGANIZATION):
1am.marconi@mfv-school.com, Students/Marconi, 1AM 1bm.marconi@mfv-school.com, Students/Marconi, 1BM 2am.arconi@mfv-school.com, Students/Marconi, 2BM ... 1af.fermi@mfv-school.com, Students/Fermi, 1AF 2af.fermi@mfv-school.com, Students/Fermi, 2AF ... 1av.volta@mfv-school.com, Students/Volta, 1AV ...
file_students.csv (SURNAME NAME EMAIL PASSWORD ORG PARENT):
"Smith", "John", "john.smith@mfv-school.com", "pw_john", "1AM", "Marconi" "Brown", "David", "david.brown@mfv-school.com", "pw_david", "1AM", "Marconi" ... "Johnson", "Kate", "kate.johnson@mfv-school.com", "pw_kate", "1AF", "Fermi" ...
make_orgs.sh
#!/bin/bash CWD=`pwd` if [ "a$1" == "a" ] ; then echo "Usage: $0 file_group_org" exit fi IFS=',' cat $1 | while read GROUP PARENT ORG do echo $PARENT $ORG python $CWD/gam.py create org $ORG description "" parent $PARENT noinherit done
make_groups.sh
#!/bin/bash CWD=`pwd` LANGUAGE=it GROUP_PREFIX="Class" GROUP_DESCRIPTION="All students in" if [ "a$1" == "a" ] ; then echo "Usage: $0 file_group_org" exit fi IFS=',' cat $1 | while read GROUP PARENT ORG do PARENT=`echo $PARENT | cut -d'/' -f2` echo $PARENT $ORG python $CWD/gam.py create group $GROUP name "$GROUP_PREFIX $ORG" description "$GROUP_DESCRIPTION $ORG - $PARENT" python $CWD/gam.py update group $GROUP primary_language "$LANGUAGE" python $CWD/gam.py update group $GROUP who_can_invite all_managers_can_invite python $CWD/gam.py update group $GROUP who_can_join invited_can_join python $CWD/gam.py update group $GROUP send_message_deny_notification true python $CWD/gam.py update group $GROUP allow_external_members false python $CWD/gam.py update group $GROUP settings who_can_post_message anyone_can_post python $CWD/gam.py update group $GROUP settings who_can_view_group all_in_domain_can_view python $CWD/gam.py update group $GROUP who_can_view_membership all_in_domain_can_view python $CWD/gam.py update group $GROUP include_in_global_address_list false done
Note: in these scripts we assumes that the organization "Sudents" already exists.
bulk_users.sh (SURNAME NAME EMAIL PASSWORD ORG PARENT):
#!/bin/bash CWD=`pwd` ROOT_ORG=Students DOMAIN=mfv-school.com if [ "a$1" == "a" ] ; then echo "Usage: $0 file_users_list" exit fi IFS=',' cat $1 | while read SURNAME NAME EMAIL PASSWORD ORG PARENT do SURNAME=$(echo $SURNAME|sed 's/"//g') NAME=$(echo $NAME|sed 's/"//g') EMAIL=$(echo $EMAIL|sed 's/"//g') PASSWORD=$(echo $PASSWORD|sed 's/"//g') ORG=$(echo $ORG|sed 's/"//g') PARENT=$(echo $PARENT|sed 's/"//g') if [ "a$EMAIL" != "a" ] ; then echo $EMAIL $ORG python $CWD/gam.py create user $EMAIL firstname "$SURNAME" lastname "$NAME" \ password $PASSWORD suspended off changepassword on \ nohash org "$ROOT_ORG/$PARENT/$ORG" mailORG=`echo $ORG | tr '[:upper:]' '[:lower:]'` mailPARENT=`echo $PARENT | tr '[:upper:]' '[:lower:]'` python $CWD/gam.py update group $mailORG.$mailPARENT@$DOMAIN add member $EMAIL fi done
Note: The script creates the accounts and puts them in their respective groups and organizations.
If you created wrong email accounts by mistake, you can correct them by a .csv file that contains the list of wrong accounts, and running the script listed below:
file_users_to_corrige.csv
"Smith", "John", "john.smith@nfv-school.org", "Smith", "James", "james.smith@nfv-school.org" ...
users-corrige.sh (SURNAME NAME EMAIL newSURNAME newNAME newEMAIL):
#!/bin/bash CWD=`pwd` if [ "a$1" == "a" ] ; then echo "Usage: $0 file_users_to_corrige" exit fi IFS=',' cat $1 | while read SURNAME NAME EMAIL newSURNAME newNAME newEMAIL do EMAIL=$(echo $EMAIL|sed 's/"//g') newSURNAME=$(echo $newSURNAME|sed 's/"//g') newNAME=$(echo $newNAME|sed 's/"//g') newEMAIL=$(echo $newEMAIL|sed 's/"//g') echo $EMAIL' --> '$newEMAIL python $CWD/gam.py update user $EMAIL username $newEMAIL firstname "$newSURNAME" lastname "$newNAME" done
Good, you should have all the files now, give execute permissions to the files .sh run them in the correct sequence, and in a few hours you will have recorded the whole school. Have fun!
cd ~/GAM ./make_orgs.sh file_group_org.csv ./make_groups.sh file_group_org.csv ./bulk_users.sh file_users_list.csv
Note: the informations and the software in this tutorial are relased "as is", without any warranty. Use at your own risk.