Running this script as distributed results in a pretty nasty pile of barf:
maint_events.sh: line 52: syntax error near unexpected token `('
maint_events.sh: line 52: ` runsql "DELETE FROM events e WHERE e.eventid IN (SELECT o.svcregainedeventid FROM outages o WHERE o.svcregainedeventid IS NOT NULL AND (ifregainedservice - iflostservice)::interval < interval '35 seconds');"'
Turns out to be a quoting problem. If I change out the double quotes around the argument to runsql, replacing them with single quotes (and of course backslash-escaping the single quote characters inside the token) then the script proceeds to the next place where runsql is called with double quotes around its sole token arg.