shell通过curl发送get请求,做一些很烦琐的事

2019-03-27 01:06|来源: 网路

概述

最近负债公司的搜索项目,索引部署采用主从模式,如果solr的core很多的话,第一次索引同步的时候,需要点击solr管理页replication项内的"replicate now" 按钮,真的很烦... ...

所以,想了一个法子解决这种情况,使用curl命令发送get请求。

步骤

1,安装curl软件,使用sudo apt-get install curl安装,当然如果已经安装就不必再浪费感情了.

2,编写shell脚本如下:

#!/bin/bash
if [ $# == 2 ]; then
  declare -a cores
  cores=("aaa" "bbb" "ccc" "ddd" "eee" "fff" "ggg" "hhh" "iii" "kkk" "ooo" "ppp")
  length=${#cores[@]}
  #log="replicate.info"
  #echo "" > $log
  for ((i=0; i<$length; i++))
  do
    echo "replicate ${cores[$i]} index ... ..."
    curl -s -o /dev/null "http://$1:$2/solr/${cores[$i]}/replication?command=fetchindex"
    #echo "------------------------------------------${cores[$i]}-------------------------------------" >> $log
    #echo `curl -s "http://$1:$2/solr/${cores[$i]}/replication?command=fetchindex"` >> $log
    #echo `curl -s "http://$1:$2/solr/${cores[$i]}/admin/replication/index.jsp?replicate=now"` >> $log
  done
else
  echo "请输入参数:[ip] [port]"
fi
exit 0

结果

好了,任务完成,测试也成功,感觉真好... ...


转自:http://www.cnblogs.com/natgeo/archive/2013/05/25/3099056

相关问答

更多
  • 这里我用cURL的POST: @ECHO OFF SET URL="http://......." SET INPUT_FILE=%1_SetClienti_in.xml SET OUTPUT_FILE=%1_SetClienti_out.xml SET CURLEXE="curl.exe" SET INPUT=%INPUT_FILE% SET OUTPUT=%OUTPUT_FILE% %CURLEXE%^ --silent^ --insecure^ -H "Content-Type: te ...
  • SSE是一种基于文本的协议,curl是一种很好的方式来排查你的连接正在发送什么。 这个命令很简单: curl http://127.0.0.1/path/to/clock.php 它输出这个: data:2015-07-07 06:19:27 data:2015-07-07 06:19:28 data:2015-07-07 06:19:29 data:2015-07-07 06:19:30 data:2015-07-07 06:19:31 data:2015-07-07 06:19:32 注意 ...
  • 我发现我得到的错误是由于服务器期待Https(443)连接而不是Http(80),这很容易通过将URL改为https://ms.4url.eu而不是http来解决://ms.4url.eu使用cURL发送请求时。 I figured out that the Error I was getting is due to the server expecting a Https(443) connection and not Http(80), this was easily solved by changin ...
  • 请求应该在application/x-www-form-urlencoded而不是JSON中,它应该是const req_body_params = "grant_type=client_credentials" ,标题为"Content-Type": "application/x-www-form-urlencoded" function AuthRequest(key) { const req_body_params = "grant_type=client_credentials"; ...
  • 在使用JavaScript处理客户端之后的任何事情,这就是为什么它不适用于curl 。 您可以使用https://www.google.com/search?q=abc上的传统非AJAX界面 它似乎会阻止你,除非你也欺骗用户代理,所以总而言之: curl \ -A 'Mozilla/5.0 (MSIE; Windows 10)' \ -o res.html \ "https://www.google.com/search?q=abc" Anything after the # is hand ...
  • PHP有一个原生的SoapClient类。 构造函数将WSDL作为参数。 这比cURL更受欢迎,因为SoapClient处理所有SOAP复杂性,它允许您处理本机对象和数组,并且无需手动构建SOAP信封和XML。 try { $client = new SoapClient('https://www.sample.com/Universal/WebService.asmx?wsdl'); $response = $client->Request(array( 'ID' => ' ...
  • 卷曲被阻挡,这意味着: $result = json_decode($ret,true); foreach ($result['data'] as $key => $value) { //process data from $result } 将不会执行,直到: $ret = curl_exec($curl); 做完了。 您可以使用curl_error()检查错误和其他问题,并使用curl_getinfo()检查HTTP响应代码。 curl is blocking, which means ...
  • 它实际上已经发送和接收HTTP / 2(draft-14版本,这是规范的预发布版本)。 您应该考虑升级curl和nghttp2库,使其说出HTTP / 2协议的最终版本(RFC 7540)。 来自服务器的提示: * ALPN, server accepted to use h2-14 curl使用HTTP / 1样式显示请求使其看起来很熟悉,但在引擎盖下它将其转换为HTTP / 2并将其发送出去。 然后服务器以HTTP / 2响应: < HTTP/2.0 200 < server:h2o/1.6.1 < ...
  • 如果有人遇到类似问题的问题,问题是由防火墙阻止我正在使用的端口引起的。 由于我在校园网络连接,解决方案是通过电子邮件发送IT来解除防火墙,以便从machineA到machineB的连接。 If anyone comes across this question with a similar issue, the problem was caused by a firewall blocking the port I was using. Since I was on campus internet conn ...
  • 据我所知,没有代码,会做两次请求。 只有一个问题 - 我在你的代码中看不到curl_exec,可以吗? 如何发送两次 - 尝试在此处添加日志 if ( curl_errno($ch) ) { $error = true; } 和这里 if($error == false){ // store that SMS was sent successfully } 这将包括当前时间,它将帮助您了解,我们多少次进入这部分脚本。 as far as i see, there is no code, ...