다음 코드가 있습니다.
curl -X POST --data-urlencode 'payload={"channel": "#general", "username": "webhookbot", "text": "This is posted to #general and comes from a bot named webhookbot.", "icon_emoji": ":ghost:"}' https://hooks.slack.com/services/xxxxxxxxxxxxxxxxxxxx
이 명령은 This is posted to #general and comes from a bot named webhookbot
다음으로 전송되었으며 Slack Channel
이제 이를 출력으로 바꾸고 싶습니다.
wc -l ips.txt | awk '{print $1}'
나는 이것을 원한다:
curl -X POST --data-urlencode 'payload={"channel": "#general", "username": "webhookbot", "text": "OUTPUT OF wc -l command , like number 154", "icon_emoji": ":ghost:"}' https://hooks.slack.com/services/xxxxxxxxxxxxxxxxxxxx
어떻게 해야 합니까?
답변1
curl -X POST --data-urlencode "payload={'channel': '#general', 'username': 'webhookbot', 'text': \"$(wc -l ips.txt | awk '{print $1}')\", 'icon_emoji': ':ghost:'}" https://hooks.slack.com/services/xxxxxxxxxxxxxxxxxxxx
답변2
명령 확장을 위해 백틱을 사용할 수 있어야 합니다.
curl -X POST --data-urlencode 'payload={"channel": "#general", "username": "webhookbot", "text": "`wc -l ips.txt | awk '{print $1}'`", "icon_emoji": ":ghost:"}' https://hooks.slack.com/services/xxxxxxxxxxxxxxxxxxxx