2016-11-30 109 views
1

我想通過EC2中的shell腳本發送AWS SNS通知。以下是我的命令:在shell腳本中向AWS SNS消息添加換行符

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})" 

我的問題是,我不知道我怎麼可以插入新行我打印使用「cat」命令文件的內容之前?我想在換行後打印文件的內容。現在它被追加到"The file contents of ..."

如何在--message參數中添加換行符?

回答

3

插入文字換行符

aws sns publish --message="... 
$(cat ${error_file})" # other options 

在bash/ksh93的/巖組:

aws sns publish --message="..."$'\n'"$(cat ${error_file})" \ 
    # other options 

使用printf

aws sns publish --message="$(printf "%s\n%s" "..." "$(cat ${error_file})")" \ 
    # other options 
+0

非常感謝魯斯蘭...的解決方案是有幫助問題解決了 – Akki