【问题标题】:Repeating post curl request until answer is 200 in bash重复发布 curl 请求,直到 bash 中的答案为 200
【发布时间】:2016-11-23 18:08:33
【问题描述】:

我在 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"
    }'

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

【问题讨论】:

    标签: bash amazon-ec2 user-data


    【解决方案1】:

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

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

    【讨论】:

    • 非常感谢。你知道我怎样才能在这个脚本中做一个“循环”,让它每 5 分钟请求一次,直到 curl 请求正常吗?
    猜你喜欢
    • 2011-09-05
    • 1970-01-01
    • 2018-01-08
    • 2021-03-28
    • 1970-01-01
    • 1970-01-01
    • 2016-01-03
    • 1970-01-01
    • 2015-12-06
    相关资源
    最近更新 更多