Question:
I want to send AWS SNS notification through shell script in EC2. The following is my command:
1 2 3 4 5 |
aws sns publish --topic-arn arn:aws:sns:x:x:x \ --region=$AWS_DEFAULT_REGION \ --subject "Processing Error - ${tablename}" \ --message "An error has occurred in API data processing. The error file ${error_file} has been written to the errors folder...The file contents of ${error_file} are : $(cat ${error_file})" |
My problem is that I don’t know how can I insert a newline before I printing the content of file using “cat
” command? I want to print the content of the file after a newline. Now it gets appended to "The file contents of ..."
.
How do I add a newline into the --message
parameter?
Answer:
Inserting the literal newline character
1 2 3 |
aws sns publish --message="... $(cat ${error_file})" # other options |
In Bash/Ksh93/Zsh:
1 2 3 4 5 6 7 |
aws sns publish --message="..." Using printf :
# other options |
Using
\n'"$(cat ${error_file})" \
# other options
printf
:
1 |