GAM Command Status Code/Exit Code

1,470 views
Skip to first unread message

Raghuram P

unread,
Oct 20, 2014, 8:24:30 AM10/20/14
to google-ap...@googlegroups.com
Hello All,

New to GAM, have browsed thru GAM documentation and was able get the basics working.

Need support in trying to find how to capture "Command Status", for example if I create / update a user, I would like to know if the operation was success or failure, and use this status code in a script that would update user entries in a database (For example when a new user is created, if user creation was success, would log a entry to database that user was created else log to a file that user creation failed).

Simply put how to capture the status/error code (for example when suspend an user that doesn't exist, 404 is shown on the screen) so that further actions can be taken inside a script. Currently using a simple perl script that updates a database and calling the gam.exe via system ("gam command") and need to know the status and also capture the output of "gam command" for further processing.

Thanks in Advance

-Raghu

Jay Lee

unread,
Oct 20, 2014, 9:02:30 AM10/20/14
to google-ap...@googlegroups.com
Any "single operation" GAM command (e.g. create user, suspend user, add member to group) that gets an API failure should return a non-zero exit code to the OS. You should be able to check for this and your script take action.




Jay Lee

--
You received this message because you are subscribed to the Google Groups "Google Apps Manager" 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 http://groups.google.com/group/google-apps-manager.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/bbe14f03-9a65-47f9-8885-4f961b1445e0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Raghuram P

unread,
Oct 21, 2014, 6:21:19 AM10/21/14
to google-ap...@googlegroups.com
Thanks for the prompt reply.

While I am doing tests from in a dos command prompt (cmd.exe) on Windows Server 2008 (32 bit) and I check %ERRORLEVEL% for "single operation" GAM command that returns error 404, the value in %ERRORLEVEL% is still set to 0.

Am i checking the correct environment variable?

-Raghu


On Monday, October 20, 2014 6:32:30 PM UTC+5:30, Jay Lee wrote:
Any "single operation" GAM command (e.g. create user, suspend user, add member to group) that gets an API failure should return a non-zero exit code to the OS. You should be able to check for this and your script take action.




Jay Lee

On Mon, Oct 20, 2014 at 8:24 AM, Raghuram P <ragr...@gmail.com> wrote:
Hello All,

New to GAM, have browsed thru GAM documentation and was able get the basics working.

Need support in trying to find how to capture "Command Status", for example if I create / update a user, I would like to know if the operation was success or failure, and use this status code in a script that would update user entries in a database (For example when a new user is created, if user creation was success, would log a entry to database that user was created else log to a file that user creation failed).

Simply put how to capture the status/error code (for example when suspend an user that doesn't exist, 404 is shown on the screen) so that further actions can be taken inside a script. Currently using a simple perl script that updates a database and calling the gam.exe via system ("gam command") and need to know the status and also capture the output of "gam command" for further processing.

Thanks in Advance

-Raghu

--
You received this message because you are subscribed to the Google Groups "Google Apps Manager" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-manager+unsub...@googlegroups.com.

Bri Hatch

unread,
Oct 21, 2014, 9:06:18 AM10/21/14
to google-ap...@googlegroups.com
On Mon, Oct 20, 2014 at 6:02 AM, Jay Lee <jay...@gmail.com> wrote:
Any "single operation" GAM command (e.g. create user, suspend user, add member to group) that gets an API failure should return a non-zero exit code to the OS. You should be able to check for this and your script take action.


It would be great if this were true, but it's not. There are numerous places where the exit code is 0 even when errors occurred. Groups seems to be a particular persnickety one. Any of these exit 0, even if the operation fails because the group doesn't exist, or the member is/isn't where expected:

gam update group real_group add    member already_in_group
gam update group real_group remove member not_in_group
gam update group non_existant_group add member real_user

One issue is that gam was exiting with upstream error codes and that doesn't make sense - Unix exit statuses are 0 through 255, so a 404 would get converted to a nonsensical 149 and such.

Ideally gam should exit with limited and meaningful exit codes, such as this:

  0 - success
  1 - permanent failure, e.g. "syntax is broken, group doesn't exist, calendar doesn't exist"
  2 - temporary failure, e.g. "can't reach api, try again"
  3 - all other failures, e.g. "you asked for multiple things but only some of them were successful."

If this would be useful, I can dig up my patch-in-progress and finish it up for inclusion upstream.

--
Bri Hatch, Systems and Security Engineer. http://www.ifokr.org/bri/

I have a deep and profound love for this new licensing set
  up. I get all misty even writing about it.
--matt

David Carter Tod

unread,
Feb 16, 2015, 10:33:18 AM2/16/15
to google-ap...@googlegroups.com
This seems like it's ongoing. When I do an update user on a non-existent user, I get a zero exit code with a "Error 404: Resource Not Found: userKey - notFound" in the output (linux).

What's the solution?

Thanks

David

David Carter Tod

unread,
Feb 16, 2015, 11:19:12 AM2/16/15
to google-ap...@googlegroups.com
Ah, perhaps found my own solution.

gam info user username@domain

does at least give a non-zero exit code (147) which would allow me to test for existence. It does mean that every create/update involves two calls (info->update or info->create) rather than potentially one (update or update->create) though.

David

Keegan Morrison

unread,
Apr 22, 2015, 11:57:32 AM4/22/15
to google-ap...@googlegroups.com
Jay do you have any updates on this issue? Returning a valid exit code would be extremely useful.

>KeegansMac$ gam update user baduser password d57f11f8casdf1569e727430ca64b4c621fc12ed sha

>updating user bad...@domain.com...

>Error 404: Resource Not Found: userKey - notFound

>KeegansMac $ echo $?

>0



On Monday, October 20, 2014 at 9:02:30 AM UTC-4, Jay Lee wrote:
Any "single operation" GAM command (e.g. create user, suspend user, add member to group) that gets an API failure should return a non-zero exit code to the OS. You should be able to check for this and your script take action.




Jay Lee

On Mon, Oct 20, 2014 at 8:24 AM, Raghuram P <ragr...@gmail.com> wrote:
Hello All,

New to GAM, have browsed thru GAM documentation and was able get the basics working.

Need support in trying to find how to capture "Command Status", for example if I create / update a user, I would like to know if the operation was success or failure, and use this status code in a script that would update user entries in a database (For example when a new user is created, if user creation was success, would log a entry to database that user was created else log to a file that user creation failed).

Simply put how to capture the status/error code (for example when suspend an user that doesn't exist, 404 is shown on the screen) so that further actions can be taken inside a script. Currently using a simple perl script that updates a database and calling the gam.exe via system ("gam command") and need to know the status and also capture the output of "gam command" for further processing.

Thanks in Advance

-Raghu

--
You received this message because you are subscribed to the Google Groups "Google Apps Manager" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-manager+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages