【发布时间】: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