Results to File

1,692 views
Skip to first unread message

Matt

unread,
Sep 8, 2011, 5:24:23 PM9/8/11
to Google Apps Manager
Is there a way to print the results to a file?

I am trying to create a log file that will show users who have
activated forwarding on their account.

The command I use is:
GAM all users show forward

I tried to use this command inside a batch file but I just ended up
with the first line of text the tool outputs in the file:
gam all users show forward >C:\log.txt

Anyone know the correct way to get this information to output?

Thanks,
Matt

Oliver Hartley

unread,
Sep 9, 2011, 7:04:31 AM9/9/11
to google-ap...@googlegroups.com

At the end of your statement add " > log.txt" withou the ".

Enviado desde mi Galaxy Tab 10.1

> --
> 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

Dan Agosto

unread,
Sep 9, 2011, 9:41:05 AM9/9/11
to google-ap...@googlegroups.com
And running this way will give you a little more information (I use loops to run commands through CSV files so I use double > (>>).

>> "c:\gam\provisiondata\logs\CreateStf.log" 2>&1

The 2>&1 writes any errors in the log file as well...then my scripts parse through the log file and create an error log for me to fix those individuals later. 

-Dan

Sandip Shah

unread,
Sep 9, 2011, 1:23:55 PM9/9/11
to Google Apps Manager
Unconventional method - do it at your own risk :-)

If you want to mess a little with code, then in version 1.9.1, line
784 is a print statement (for function getForward)

Insert this before the print line

tempx = sys.stdout
sys.stdout = open('myfilename', 'w')

and this after that line

sys.stdout = tempx

It will redirect all the stdout to a file - you will not get any
printed messages, and everything will go to a file.


I would even go a step farther and replace the function with this
piece of code.

def getForward(users):
import csv
f = open('myfilename', 'wb')
writer = csv.writer(f)
emailsettings = getEmailSettingsObject()
for user in users:
if user.find('@') > 0:
emailsettings.domain = user[user.find('@')+1:]
user = user[:user.find('@')]
else:
emailsettings.domain = domain
forward = emailsettings.GetForward(username=user)
print "User %s: Forward To:%s Enabled:%s Action:%s" % (user,
forward['forwardTo'], forward['enable'], forward['action'])
writer.writerows(user, forward['forwardTo'], forward['enable'],
forward['action'])

This will give you both - a csv output to a file and messages on
stdout too.

Good Luck.

SS

On Sep 9, 6:41 am, Dan Agosto <danago...@gmail.com> wrote:
> And running this way will give you a little more information (I use loops to
> run commands through CSV files so I use double > (>>).
>
> >> "c:\gam\provisiondata\logs\CreateStf.log" 2>&1
>
> The 2>&1 writes any errors in the log file as well...then my scripts parse
> through the log file and create an error log for me to fix those individuals
> later.
>
> -Dan
>
> On Fri, Sep 9, 2011 at 6:04 AM, Oliver Hartley <
>
>
>
>
>
>
>
> oliver.hart...@solucionesorion.com> wrote:
> > At the end of your statement add " > log.txt" withou the ".
>
> > Enviado desde mi Galaxy Tab 10.1
Reply all
Reply to author
Forward
0 new messages