$ cat mongo.sh
#!/bin/bash
output="mongo.out"
>$output
cat mongoserver.txt |while read host 
do
echo $host >>$output
./mongo --quiet $host cmd.js >> $output
done
$ cat cmd.js
var isMaster = db.isMaster().ismaster
if(!isMaster)
 db.getMongo().setSlaveOk()
var setname=db.adminCommand("replSetGetStatus").set
print(setname)
var members=db.adminCommand("replSetGetStatus").members
members.forEach(function(item) {     print(item.stateStr+","+item.name+","+item.name.split(":",1)); })
//db.adminCommand("listDatabases").databases.sort(function(l, r) {return r.sizeOnDisk - l.sizeOnDisk}).forEach(function(d) {if(!d.empty)print(d.name + "," + (d.sizeOnDisk/1024/1024/1024).toFixed(2) + "GB") });
db.adminCommand("listDatabases").databases.sort(function(l, r) {return r.sizeOnDisk - l.sizeOnDisk}).forEach(function(d) {if(!d.empty&&d.name!="local"&&d.name!="admin"&&d.name!="test"){db=db.getSiblingDB(d.name);var doc=db.runCommand({dbstats : 1});print(doc.db+",fileSize:"+(doc.fileSize/1024/1024/1024).toFixed(2)+" GB"+",dataSize:"+doc.dataSize+",collections:"+doc.collections+",objects:"+doc.objects+",index:"+doc.indexes+",indexSize:"+doc.indexSize)}})

ccj 于 17 天前 修改
0 回复
需要 登录 后方可回复, 如果你还没有账号你可以 注册 一个帐号。