Akk*_*kki 3 linux shell amazon-ec2 amazon-web-services amazon-sns
我想通过EC2中的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})"
Run Code Online (Sandbox Code Playgroud)
我的问题是我不知道在使用" cat"命令打印文件内容之前如何插入换行符?我想在换行后打印文件的内容.现在它被附加到"The file contents of ...".
如何在--message参数中添加换行符?
插入文字换行符
aws sns publish --message="...
$(cat ${error_file})" # other options
Run Code Online (Sandbox Code Playgroud)
在Bash/Ksh93/Zsh中:
aws sns publish --message="..."$'\n'"$(cat ${error_file})" \
# other options
Run Code Online (Sandbox Code Playgroud)
使用printf:
aws sns publish --message="$(printf "%s\n%s" "..." "$(cat ${error_file})")" \
# other options
Run Code Online (Sandbox Code Playgroud)