Bash script to create a replica set

Thank you very much for you reply and you are right.

But is still got the same problem.

if i put the code in my bash

#!/bin/bash

sudo systemctl enable mongod
sudo systemctl start mongod

mongo rs.initiate({
    _id : 'rs0',
    members: [
        {'_id': 0, 'host': '10.0.1.100:27017' },
        {'_id': 1, 'host': '10.0.2.100:27017' },
        {'_id': 2, 'host': '10.0.3.100:27017' }
    ]
})

and run my instance, it seems that mongo console does not execute this code. but if the instance is up and running, and i access mongo console and paste the same code, than it works just fine.