I am trying to run this command from bash script:
mongo 192.168.10.20:27000 --eval \"use admin && db.shutdownServer() && quit()\"
There are differences between interactive & scripted mongo shell sessions. In particular, commands like use admin
are not valid JavaScript and will only work in an interactive shell session.
The working equivalent of your shutdown command line would be:
mongo 192.168.10.20:27000/admin --eval "db.shutdownServer()"
You can include the database to use in the connection string, and there is no need to quit from a scripted mongo
shell session.
If you do need to change databases from a scripted session, there is a db.getSiblingDB() JavaScript function. An alternative way to write the shutdown command above would be:
mongo 192.168.10.20:27000 --eval "db=db.getSiblingDB('admin');db.shutdownServer()"