Delete recurring events gam calendar

3,631 views
Skip to first unread message

Dennis M

unread,
Aug 14, 2018, 12:32:45 PM8/14/18
to GAM for G Suite
Hey Everyone,

I just ran through a script to delete a BUNCH of events, it was great!  Then I realized it was only deleting the original occurrence and not the reoccurring events... Is this possible with gam?  It looks like the event ids are just slightly different based on the date.



(A sync tool caused a bunch of dups)

Best,
Dennis

Ross Scroggs

unread,
Aug 14, 2018, 12:48:44 PM8/14/18
to google-ap...@googlegroups.com
Dennis,

How did you delete the events?

Ross

This message contains information which may be confidential and/or protected by attorney-client privilege.  Unless you are the addressee, you may not use, copy or disclose to anyone this message or any information contained in this message.  If you have received this message in error, please send me an email and delete this message.   Thank you.

--
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/b76a6d5d-a4cb-45a4-9dcf-6a172a7db979%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

Dennis M

unread,
Aug 14, 2018, 12:57:17 PM8/14/18
to GAM for G Suite

gam calendar [usersemail] deleteevent eventid ~EventId doit


This using a CSV


On Tuesday, August 14, 2018 at 12:48:44 PM UTC-4, Ross Scroggs wrote:
Dennis,

How did you delete the events?

Ross

On Tue, Aug 14, 2018 at 9:32 AM Dennis M <dennis...@cellsignal.com> wrote:
Hey Everyone,

I just ran through a script to delete a BUNCH of events, it was great!  Then I realized it was only deleting the original occurrence and not the reoccurring events... Is this possible with gam?  It looks like the event ids are just slightly different based on the date.



(A sync tool caused a bunch of dups)

Best,
Dennis

This message contains information which may be confidential and/or protected by attorney-client privilege.  Unless you are the addressee, you may not use, copy or disclose to anyone this message or any information contained in this message.  If you have received this message in error, please send me an email and delete this message.   Thank you.

--
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-manager+unsub...@googlegroups.com.


--

Dennis M

unread,
Aug 14, 2018, 1:12:27 PM8/14/18
to GAM for G Suite
I think i got it!

events are like this

cf9l9id32cg8f6c4io1uti22m0_20181115T200000Z

It appears if i remove the _date and make it just the first half of the string it works

cf9l9id32cg8f6c4io1uti22m0

 Now I just have to remove all the dates somehow 

Peter Smulders

unread,
Aug 14, 2018, 6:04:11 PM8/14/18
to GAM for G Suite
Hi Dennis

If you have a csv file that has one column, being the eventid (with the dates), then this will be what you need:

$ (echo "EventID"; tail +2 your_file_with_eventids.csv | sed 's/^\(.*\)_.*$/\1/' | sort -u ) | gam csv - gam calendar your_user@your_domain.com deleteevent ~EventID doit

The first part (between brackets) recreates the csv file 'on the fly' by spitting out a header followed by the event IDs without the part after the underscore, and deduped for good measure. The second part is a special way of invoking 'gam csv' by using a '-' instead of the file name, so that gam will not read from a file, but from STDIN ('standard input'), in this case what the first part spits out.

Try it without the 'doit' off course, but this should work even if there are underscores in the first part of the EventID.

You could off course modify the source where you got the EventIDs in the first place, or edit them and create another CSV file, but this approach leaves what you have and solves it, since this sounds like a one-off exercise for your situation.

--peter

Dennis M

unread,
Aug 15, 2018, 3:20:34 PM8/15/18
to GAM for G Suite
Hey Peter,

Thanks so much ! 

I was not aware that i could pass STDIN with the - , thats awesome to know.

I ended up using BBedit and a regex to get rid of the dates.

Thanks,
Dennis

On Tuesday, August 14, 2018 at 6:04:11 PM UTC-4, Peter Smulders wrote:
Hi Dennis

events are like this

cf9l9id32cg8f6c4io1uti22m0_20181115T200000Z

It appears if i remove the _date and make it just the first half of the string it works

cf9l9id32cg8f6c4io1uti22m0

 Now I just have to remove all the dates somehow 

If you have a csv file that has one column, being the eventid (with the dates), then this will be what you need:

$ (echo "EventID"; tail +2 your_file_with_eventids.csv | sed 's/^\(.*\)_.*$/\1/' | sort -u ) | gam csv - gam calendar your...@your_domain.com deleteevent ~EventID doit

Peter Smulders

unread,
Aug 16, 2018, 6:53:32 PM8/16/18
to GAM for G Suite
I was not aware that i could pass STDIN with the - , thats awesome to know.

This works with both gam csv and gam batch.

For all you command line hacks and scripters: I regularly deal with situations where I have to do the same gam thing to 140 items that are not dependant on each other. It is easy enough to to for loops on a command line, but in some cases, that ends up taking a long time. To speed things up, I do this:

$ (for A in 1 2 3 4 5 6 7 8; do
echo gam whatever argument argument2 ${A} argument3
done ) | gam batch -

You need to be careful with arguments that have spaces and quoting etc and when one or more processes throw errors it becomes difficult to figure out what happened, but for simple cases you can take advantage of concurrent (i.e. parallel) processes. The 'magic' lies in the use of the brackets: known in bash parlance as a 'subshell' it is a way to group a number of commands and have all their output bundled as if there was only one. Whatever happens within a subshell stays there, so you automatically get protection from scope conflicts and you can mess with environment variables without having to manually restore them. For example:

$ gam info something something csv

will output data in a csv format. If you wanted to grab those data elements and do something with them, you could do:

$ gam info something something csv | awk -F',' '{print $2 $3}' | while read FirstDataElement SecondDataElement; do
   echo "This is the first: ${FirstDataElement}"
   echo "This is the secondt: ${SecondDataElement}"
done

The awk bit chops up the csv line and spits out the second and third element, which you use as first and second, respectively.

Easier way with a subshell:

$ gam info something something csv | (
IFS=","
while read DUMMY FirstDataElement SecondDataElement; do
   echo "This is the first: ${FirstDataElement}"
   echo "This is the secondt: ${SecondDataElement}"
done)

The DUMMY catches (and ignores) the first item on the line; the rest of the command is identical. By changing the Internal Field Seperator (IFS) from the default space(s)/tab(s) to a comma, we let bash do the splitting of the csv line; no awk needed. Because the subshell ends (and disappears) after the closing ), there is no need to (re)set the IFS.

--peter
Reply all
Reply to author
Forward
0 new messages