Notes on the settings

View My GitHub Profile

How to send job notifications to slack

Send job notifications to Gmail

#$ -S /usr/bin/bash  
#$ -cwd
#$ -q xe2.q
#$ -pe x12 12
#$ -M <your-gmail-address>
#$ -m bea
#$ -j y
#$ -N test

echo 'test'

m option

-m b|e|a|s|n,...
          `b'     Mail is sent at the beginning of the job.
          `e'     Mail is sent at the end of the job.
          `a'     Mail is sent when the job is aborted or
                  rescheduled.
          `s'     Mail is sent when the job is suspended.
          `n'     No mail is sent.

Notify Gmail to your slack channel

function main() {
  const threads = GmailApp.search('in:Inbox is:Unread from:root', 0, 100)
  
  threads.forEach((thread) => {
    thread.getMessages().forEach((message) => {
      if (!message.isUnread()) { return }
      const text = create_message(message)
      send_to_slack(text)
      message.markRead()
    })
  })
}

function create_message(message) {
  // ↓ replace <@U02P2353B7Y> to your slack id
  return  `<@U02P2353B7Y> \n` 
          +`[Date] ${message.getDate()}`
          + `\n[From] ${message.getFrom()}` 
          + `\n[Subject] ${message.getSubject()}`
          + `\n[Body]\n${message.getPlainBody()}`
}

function send_to_slack(text) {
  const webhook_url = <your-app-webhook-url>
  const headers = { "Content-type": "application/json" }
  const data = { "text": text }
  const options = {
    "method": "post",
    "headers": headers,
    "payload": JSON.stringify(data),
    "muteHttpExceptions": true
  }
  UrlFetchApp.fetch(webhook_url, options)
}