系统相关
首页 > 系统相关> > linux – 在shell脚本中为AWS SNS消息添加换行符

linux – 在shell脚本中为AWS 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})"

我的问题是我不知道在使用“cat”命令打印文件内容之前如何插入换行符?我想在换行后打印文件的内容.现在它被附加到“……的文件内容”.

如何在–message参数中添加换行符?

解决方法:

插入文字换行符

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

在Bash / Ksh93 / Zsh中:

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

使用printf:

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

标签:amazon-sns,linux,shell,amazon-web-services,amazon-ec2
来源: https://codeday.me/bug/20190823/1702243.html