【问题标题】:curl: (52) Empty reply from server for mongodbcurl: (52) 服务器对 mongodb 的回复为空
【发布时间】:2023-02-26 14:49:24
【问题描述】:
#!/bin/bash

# Set the MongoDB connection information
mongo_host="172.16.10.10"
mongo_port="27017"
mongo_db="user_info_remote"
mongo_collection="user_info"

# Extract user information from /etc/passwd for users with UID greater than 500 and insert it into MongoDB
awk -F: '$3>=500 {print "{\"username\":\""$1"\",\"uid\":"$3",\"gid\":"$4",\"home\":\""$6"\",\"shell\":\""$7"\"}"}' /etc/passwd \
  | while read user_info; do
    curl -vvv -i -H "Content-Type: application/json" -X POST -d "$user_info" "http://$mongo_host:$mongo_port/$mongo_db/$mongo_collection"
  done

# Echo a message to the console
echo "User information stored in MongoDB"

这是我试图执行的脚本,但出现以下错误

------------------来自命令行的日志----------------

*   Trying 172.16.10.10..

* TCP_NODELAY set

* Connected to 172.16.10.10 (172.16.10.10) port 27017 (#0)

\> POST /user_info_remote/user_info HTTP/1.1

\> Host: 172.16.10.10:27017

\> User-Agent: curl/7.61.1

\> Accept: */*

\> Content-Type: application/json

\> Content-Length: 86

\>

* upload completely sent off: 86 out of 86 bytes

* Empty reply from server

* Connection #0 to host 172.16.10.10 left intact

curl: (52) Empty reply from server

存储在MongoDB中的用户信息

谁能指导我?我是 mongodb 的新手

在这里,请注意,mongo db 配置文件绑定是为所有 ip4 IP 配置的,我使用 telnet 和 curl 从删除机器中检查并且端口已打开。

curl -vv telnet://172.16.10.10:27017

* Rebuilt URL to: telnet://172.16.10.10:27017/

*   Trying 172.16.10.10...

* TCP_NODELAY set

* Connected to 172.16.10.10 (172.16.10.10) port 27017 (#0)

我正在尝试构建一个脚本,该脚本将从 cat /etc/passwd 文件中收集用户信息并将该数据存储到 MongoDB 数据库中。

【问题讨论】:

  • 查询 mongodb 的标准工具是mongo,你为什么不使用它?
  • 我有 300 多台服务器,为此我可能必须在所有那台机器上安装软件包,所以我想知道是否还有其他替代方法

标签: linux database mongodb mongodb-query


【解决方案1】:

大声笑,看来你基本上是从 chatgpt 复制一个 sn-p 并抱怨它不起作用? 你能不能至少做一些研究并检查/var/log/mongodb? 这不是“您执行的脚本”。这是您复制过来的脚本,甚至不知道复制脚本失败的原因。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-05
    • 1970-01-01
    • 2021-05-07
    • 2015-05-05
    • 2010-12-27
    • 1970-01-01
    相关资源
    最近更新 更多