Help with bash script?

478 views
Skip to first unread message

JP Connolly

unread,
Aug 24, 2012, 3:18:53 PM8/24/12
to google-apps-manager
Hey all - 

A rather spectacular headache is making this more tricky than it should be. I'm trying to modify the Unix script found here to allow me to mass-update all groups prior to the start of the school year after a mass/total group member purge. I'm running GAM 2.51 off of OSX 10.7.4, and have never had any issues with GAM. I'm stumped as to why this script isn't working on OSX. The input users.csv file will have three columns (left to right) with the group's name, the role (member/owner) and the user's e-mail. This should then in theory issue a command per group user that will re-add them with the correct role. 

However, when I run it at the command line (saved as groupupdate.sh with chmod +x permissions set) with "sudo sh groupupdate.sh" absolutely nothing happens. The script file is in the same path/folder as gam.py and the users.csv file. 

Help?

Here's the script


#!/bin/bash

gam_command() {
  python gam.py update group "$group" add "$role" "$email"
  }

IFS=,
x=1
while read group role email; do
  email=${email//\"/}
  role=${role//\"/}
  group=${group//\"/}
  gam_command $group $role $email $org $x &
  while (( $(jobs | wc -l) >= 20 )); do
    sleep 0.1
    jobs > /dev/null
    done
  x=$(($x+1))
  if [ $x -gt 20 ]
  then
    x=1
  fi
done < users.csv

wait


--
JP Connolly
Director of Technology
Saint Ann's School
129 Pierrepont St.
Brooklyn, NY 11201

Adelson Junior

unread,
Aug 24, 2012, 4:18:14 PM8/24/12
to google-ap...@googlegroups.com
Hello,

I've tried to run the script here on Linux and it worked correctly.
I am not experienced with OSX but, have you tried to run with ./groupupdate.sh command line only ?

Att,
Adelson.

2012/8/24 JP Connolly <jpcon...@saintannsny.org>
--
You received this message because you are subscribed to the "Google Apps Manager" group.
To post to this group, send email to
google-ap...@googlegroups.com
To unsubscribe from this group, send email to
google-apps-man...@googlegroups.com
For more options, visit this group at
https://groups.google.com/forum/#!forum/google-apps-manager

JP Connolly

unread,
Aug 24, 2012, 4:23:18 PM8/24/12
to google-ap...@googlegroups.com
It fails as well. Perhaps there are some command syntax differences between the two? 

Adelson Junior

unread,
Aug 24, 2012, 4:25:22 PM8/24/12
to google-ap...@googlegroups.com
And not errors at all?

Att,

Adelson O. Junior

Multiedro Cloud Services
ade...@multiedro.com.br

Av. 9 de julho, 5617, 5o. andar, CEP 01407-200, São Paulo, SP, Brasil

 





2012/8/24 JP Connolly <jpcon...@saintannsny.org>

JP Connolly

unread,
Aug 24, 2012, 4:26:20 PM8/24/12
to google-ap...@googlegroups.com
Just returns to the command line instantly :(

Jay Lee

unread,
Aug 24, 2012, 4:30:34 PM8/24/12
to google-ap...@googlegroups.com
Try running:

"bash groupupdate.sh"

There's no reason to run the GAM command as root (sudo) and Bash should be used instead of sh.

Regards,

Jay Lee
LCS Deployment Lead   |  ⚡ Dito

Adelson Junior

unread,
Aug 24, 2012, 4:30:57 PM8/24/12
to google-ap...@googlegroups.com

Try this command:
# wc -l groupupdate.sh

And give us the result.

JP Connolly

unread,
Aug 24, 2012, 4:37:39 PM8/24/12
to google-ap...@googlegroups.com
25 allgroups.sh 

The file was put together using nano. 

(I changed the name to test something else). 

Also, Jay - running the command with bash yields the same non-run/error. 

Jay Lee

unread,
Aug 24, 2012, 4:45:55 PM8/24/12
to google-ap...@googlegroups.com
Well... Anyone want to buy me a Mac for testing?  If they did I'd pretty much guarantee I could get this working :-)


Regards,

Jay Lee
LCS Deployment Lead   |  ⚡ Dito



JP Connolly

unread,
Aug 24, 2012, 4:47:52 PM8/24/12
to google-ap...@googlegroups.com
I'll try this same script on our Ubuntu server with GAM and see what happens. 

Adelson Junior

unread,
Aug 24, 2012, 4:52:41 PM8/24/12
to google-ap...@googlegroups.com
I think it may be because in macosx the default end of line is the Line Feed.

\n = CR (Carriage Return) // Used as a new line character in Unix
\r = LF (Line Feed) // Used as a new line character in Mac OS

Do you have the vim editor?
If yes, open the file and run the command inside vim

:set list
With this command you can see what is the end of line used.

^M -> CR
$ -> LF

If the end of line is LF, try to change with this command:

#cat groupupdate.sh | sed 's/\r/\n/g'  > groupupdate-modified.sh

Then Run it.

Att,

Adelson O. Junior

Multiedro Cloud Services
ade...@multiedro.com.br

Av. 9 de julho, 5617, 5o. andar, CEP 01407-200, São Paulo, SP, Brasil

 





2012/8/24 Jay Lee <j...@ditoweb.com>

JP Connolly

unread,
Aug 24, 2012, 4:57:44 PM8/24/12
to google-ap...@googlegroups.com
I changed the EOL type in text wrangler (it was actually set to LF, so I set it to CR and re-saved). No dice. I'm just going to try on our Linux box. 

Thanks for youur help! 

JP Connolly

unread,
Aug 25, 2012, 10:59:47 AM8/25/12
to google-ap...@googlegroups.com
Just to close this loop, something is fsck'd with my work machine. The code below works dandy on my Mac at home. On a related note, anyone know how to reset the IFS environment/settings to default (whatever that may be?). 

Jay, you should set up a Mac donation page/Paypal - there's more than enough gratitude for GAM out there to earn you a beastly quad-core Mac :) 

-JP
Reply all
Reply to author
Forward
0 new messages