【发布时间】:2017-05-01 22:08:16
【问题描述】:
我的 bash shell 脚本中有以下行;
inotifywait -e "$EVENTS" -m -r --format '%T %:e %w%f' --timefmt "%a, %b %d %l:%M.%S" ${basedir} | grep "${filetype}"
每当执行该行时,这将输出类似于 "Mon, May 01 9:29.20 DELETE /home/ubuntu/test/test.php" 的行。
是否可以将以上输出直接通过管道传输到 AWS SNS?我尝试在重定向之前使用 jq 将输出格式化为 json,但是如下使用时没有输出。
inotifywait -e "$EVENTS" -m -r --format '%T %:e %w%f' --timefmt "%a, %b %d %l:%M.%S" ${basedir} | grep "${filetype}" | jq -R -s -c 'split("\n")'
而且直接 pipping 输出是行不通的。
inotifywait -e "$EVENTS" -m -r --format '%T %:e %w%f' --timefmt "%a, %b %d %l:%M.%S" ${basedir} | grep "${filetype}" | aws sns publish --topic-arn "${sns}"
【问题讨论】:
-
将
grep的结果倒入标准输出会发生什么? -
为什么要格式化成json?似乎您需要将其解析为请求参数(请参阅a sample request)。顺便说一句,为什么不使用CLI?
-
我得到我想要的输出作为一个字符串。例如:“5 月 1 日星期一 9:29.20 删除 /home/ubuntu/test/test.php”
-
我正在尝试使用 CLI,但据我了解,我需要将 JSON 字符串传递给它?
-
哎呀我没注意到,划掉那个:/
标签: bash shell amazon-web-services amazon-sns