I am attempting to write a script in bash that monitors certain aspects of a server, and sends a message to slack if it notices that something is wrong. However, I am running into a strange set of error messages that leads me to believe the syntax of my script is a little off. Here is the code in question:
message=("Please go to this website: www.google.com" "Please go to this website: www.github.com" "Please go to this website: www.wikipedia.com") for j in seq `0 2`; do curl -X POST -H 'Content-type: application/json' --data '{"text":"<!channel> '${message[$j]}' "}' https://hooks.slack.com/services/AN_ID/ANOTHER_ID/SOME_ID# Slack with channel mention done
When I run this code, it should send a message to the specified slack group, stating each of the specified lines of text, for example "@channel Please go to this website: www.google.com"
When I run this, I receive the following error messages:
curl: (6) Could not resolve host: go curl: (6) Could not resolve host: to curl: (6) Could not resolve host: this curl: (6) Could not resolve host: website: curl: (3) [globbing] unmatched close brace/bracket in column 34 invalid_payloadcurl: (6) Could not resolve host: go curl: (6) Could not resolve host: to curl: (6) Could not resolve host: this curl: (6) Could not resolve host: website: curl: (3) [globbing] unmatched close brace/bracket in column 33
Does anybody have any insights on how to resolve these error messages? I am thinking it has something to do with the way I have written the array of strings, but I can't identify the issue.
--data '{"text":"<!channel> '"${message[$j]}"' "}'
?seq
arguments. Use`seq 0 2`
and it should work as expected.