重复post curl请求,直到bash中的答案为200

时间:2016-11-23 18:08:34

标签: bash amazon-ec2 user-data

我在ec2 linux的用户数据中有这个脚本。有没有办法在这个脚本中“循环”一段时间,以便它每5分钟继续执行curl请求,直到请求返回200?

#!/bin/bash
      sed -i -e '/<Name>loadbalanceServerIP<\/Name>/,/<Value>/s/<Value>[^<]*/<Value>52.53.197.227/' /home/wowza/conf/Server.xml
      edge_ip=`curl -s http://169.254.169.254/latest/meta-data/public-ipv4`
    curl --digest -u 'wowza:i-0fbfeb0718fab03b8' -X POST --header 'Accept:application/json; charset=utf-8' --header 'Content-type:application/json; charset=utf-8' http://52.53.197.227:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/live/pushpublish/mapentries/letitoptier_source -d'
    {
      "restURI":          "http://52.53.197.227:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/live/pushpublish/mapentries/letitoptier_source",
      "serverName":       "_defaultServer_",
      "sourceStreamName": "letitoptier_source",
      "entryName":        "letitoptier_source_target",
      "profile":          "rtmp",
      "host":             "'$edge_ip'",
      "application":      "live",
      "userName":         "wowza",
      "password":         "i-0fbfeb0718fab03b8",
      "streamName":       "letitoptier_source"
    }'
    curl --digest -u 'wowza:i-0fbfeb0718fab03b8' -X POST --header 'Accept:application/json; charset=utf-8' --header 'Content-type:application/json; charset=utf-8' http://52.53.197.227:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/live/pushpublish/mapentries/letitoptier_160p -d'
    {
      "restURI":          "http://52.53.197.227:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/live/pushpublish/mapentries/letitoptier_160p",
      "serverName":       "_defaultServer_",
      "sourceStreamName": "letitoptier_160p",
      "entryName":        "letitoptier_160p_target",
      "profile":          "rtmp",
      "host":             "'$edge_ip'",
      "application":      "live",
      "userName":         "wowza",
      "password":         "i-0fbfeb0718fab03b8",
      "streamName":       "letitoptier_160p"
    }'

我怎么知道它是否运行以及它返回了什么结果或消息? 谢谢

1 个答案:

答案 0 :(得分:1)

如果您不确定是否已执行用户数据脚本,则可在以下位置获取日志文件:

  • Linux:/var/log/cloud-init-output.log
  • Windows:C:\cfn