I am trying to create replica but unable to proceed
Script to create 3 mongod instance :
sudo mkdir -p /data/rs1 /data/rs2 /data/rs3
sudo mongod --replSet rs1 --logpath "1.log" --dbpath /data/rs1 --port 27017 --fork
sudo  mongod --replSet rs2 --logpath "2.log" --dbpath /data/rs2 --port 27018 --fork
sudo mongod --replSet rs3 --logpath "3.log" --dbpath /data/rs3 --port 27019 --fork
This executes successfully but after this i try to provide rs1 information about rs2 and rs3 via below script :
init_replica.js :
config = {
            _id:"rs1",members:[
            {_id:0,host:"grit-lenevo-pc:27017",priority:0,slaveDelay:5},
            {_id:1,host:"grit-lenevo-pc:27018"},
            {_id:2,host:"grit-lenevo-pc:27019"}]
}
rs.initiate(config) 
rs.status()
Now when i try to run :
mongo --port 27018 < init_replica.js
I am getting :
MongoDB shell version: 3.2.8
connecting to: 127.0.0.1:27018/test
{
    "_id" : "rs1",
    "members" : [
        {
            "_id" : 0,
            "host" : "grit-lenevo-pc:27017",
            "priority" : 0,
            "slaveDelay" : 5
        },
        {
            "_id" : 1,
            "host" : "grit-lenevo-pc:27018"
        },
        {
            "_id" : 2,
            "host" : "grit-lenevo-pc:27019"
        }
    ]
}
{
    "ok" : 0,
    "errmsg" : "Attempting to initiate a replica set with name rs1, but command line reports rs2; rejecting",
    "code" : 93
}
{
    "info" : "run rs.initiate(...) if not yet done for the set",
    "ok" : 0,
    "errmsg" : "no replset config has been received",
    "code" : 94
}
bye
Note : The same command works fine if i try below command :
mongo --port 27017 < init_replica.js
Following tutorials : M101 Mongo Db For Java Developers