sh 将命令执行结果通知给Slack(传入Webhooks)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 将命令执行结果通知给Slack(传入Webhooks)相关的知识,希望对你有一定的参考价值。

#!/bin/sh

WORK_DIR="/where/to/work/directory"
cd $WORK_DIR || exit # In crontab, it may needs moving into work directory from default directory (home directory)

LS_FILES="$(ls -l file*)" # Wants notify this result

notifyToSlack() {
  # In crontab, make sure to the curl command (or other commands) is full path.
  /usr/bin/curl -X POST -H 'Content-type: application/json' \
    --data "$1" \
    https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
}
notifyToSlack "{\"text\": \"\`\`\`\n$LS_FILES\n\`\`\`\"}"

以上是关于sh 将命令执行结果通知给Slack(传入Webhooks)的主要内容,如果未能解决你的问题,请参考以下文章