Are you sure about this? It would be better if you explicitly print out the returned status of each command (it's returned as json so you have to use printjson rather than print.
$ mongo --quiet --eval "printjson(rs.initiate());printjson(rs.add('host1:port1'));printjson(rs.add('host2:port2'))"
{ "ok" : 0, "errmsg" : "server is not running with --replSet" }
{ "ok" : 0, "errmsg" : "not running with --replSet" }
{ "ok" : 0, "errmsg" : "not running with --replSet" }
Obviously I got errors from all because I'm not running the mongod I sent these to with replSet option :)
Rather than sending all the commands as a single line to eval why not put them into a script file (.js file)?
initRepl.js
var statusInit = rs.initiate();
var statusAdd1 = rs.add('host1:port1');
var statusAdd2 = rs.add('host2:port2');
if (statusInit.ok==0 || statusAdd1.ok==0 || statusAdd2.ok==0) {
print("Not everything was okay! \n" + tojson(statusInit) + "\n" + tojson(statusAdd1) + "\n" + tojson(statusAdd2));
}
Now run this with
$ mongo --quiet initRepl.js
Not everything was okay!
{ "ok" : 0, "errmsg" : "server is not running with --replSet" }
{ "ok" : 0, "errmsg" : "not running with --replSet" }
{ "ok" : 0, "errmsg" : "not running with --replSet" }
$
Makes it a lot more manageable and you can add a lot more functionality and error checking, etc. Plus it's in a file so you can rerun it in the future whereas command history may disappear.
Asya