Running a command in another cli


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running a command in another cli
# 1  
Old 04-04-2017
Running a command in another cli

I am writing a script to login to to a mongo DB node and get the status of that machine. The usual work flow is :

Code:
[root@mongodb-secondary-1 ~]# mongo admin -u root -p root 
MongoDB shell version: 3.0.11
connecting to: admin
rs0:SECONDARY>

Then in the new prompt I can run a command to check status :


Code:
rs0:SECONDARY> rs.status()
{
	"set" : "rs0",
	"date" : ISODate("2017-04-04T19:24:56.369Z"),
	"myState" : 2,
	"syncingTo" : "172.29.219.108:27017",
	"members" : [
		{
			"_id" : 0,
			"name" : "172.29.219.108:27017",
.
.
.

Now since I am loging into from another node, I want this all in one shot. Something like :

Code:
mongo admin -u root -p root ; rs.status()

But unfortunately this does not work. Any idea how I can send a command to another application CLI and get the status ?

---------- Post updated at 12:31 AM ---------- Previous update was at 12:26 AM ----------

Got the solution :

Code:
mongo admin -u root -p root --quiet --eval 'printjson(rs.status())'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Arduino-cli - Uploading to Unknown Chinese Arduino Boards using the Arduino Command Line Interface

In my further exploration of Arduino, today I decided to install the arduino-cli on my mac today. https://github.com/arduino/arduino-cli I followed the instructions for macOS but when I got to this part: arduino-cli board list I got the dreaded "Unknown" Fully Qualified Board Name... (1 Reply)
Discussion started by: Neo
1 Replies

2. UNIX for Beginners Questions & Answers

Another one line command where I'd like to determine if Ubuntu or Red Hat when running command

Hello Forum, I'm making very good progress on my report thanks to the very helpful people on this forum. I've been able to successfully create my report for my Red Hat servers. But I do have a few ubuntu servers in the mix and I'd like to capture some data from them when an ssh connection is... (8 Replies)
Discussion started by: greavette
8 Replies

3. AIX

I'm facing problem with rpm command, when running the command and appears this error:

exec(): 0509-036 Cannot load program /usr/opt/freeware/bin/rpm because of the following errors: 0509-022 Cannot load module /opt/freeware/lib/libintl.a(libintl.so.1). 0509-150 Dependent module /opt/freeware/lib/libiconv.a(shr4.o) could not be loaded. 0509-152 Member... (4 Replies)
Discussion started by: Ohmkar
4 Replies

4. UNIX for Dummies Questions & Answers

Conversion program/command via CLI

I already know about the docx2txt program, and it's extremely helpful. ssconvert is also really helpful, but unlike docx2txt, it works both ways. How does one convert a .txt file to .docx via CLI, or is it even possible?? This: docx2txt example.docx results in making a .txt file out of... (2 Replies)
Discussion started by: Huitzilopochtli
2 Replies

5. AIX

Command to see the status of managed node from CLI of HMC?

Folks, Asking a silly question - is there a way to know the status(Power Off/Running) of a managed node from CLI of HMC, alike the way we see it for the LPARs running on the node from 'vtmenu'? Most of us use the UI to see the status of the LPARs/Managed node - but just inquisitive to know if... (4 Replies)
Discussion started by: thisissouvik
4 Replies

6. Shell Programming and Scripting

Command to check only Autosys running jobs with autorep like command

Hi, Is there any specific command to use to check only say Running jobs via autorep or similar command for Autosys? (0 Replies)
Discussion started by: sidnow
0 Replies

7. Linux

Way to execute a command from CLI

OS : Linux Kernel ver : 2.6x Is there any legit difference between way that shell interprets the below mentioned command lines in Linux environment? Option A> . <exec_file_name> arg1 agr2 Option B> ./<exec_file_name> arg1 agr2 The reason for me asking this silly question is... (2 Replies)
Discussion started by: kumarjt
2 Replies

8. UNIX for Dummies Questions & Answers

Running set options from the command line and bash command

I'm reading about debugging aids in bash and have come across the set command. It says in my little book that an addition to typing set you can also use them "on the command line when running a script..." and it lists this in a small table: set -o option Command Line... (5 Replies)
Discussion started by: Straitsfan
5 Replies

9. SuSE

inconsistent ls command display at the command prompt & running as a cron job

Sir, I using the following commands in a file (part of a bigger script): #!/bin/bash cd /opt/oracle/bin ls -lt | tail -1 | awk '{print $6}' >> /tmp/ramb.out If I run this from the command prompt the result is: 2007-05-16 if I run it as a cron job then... (5 Replies)
Discussion started by: rajranibl
5 Replies

10. Shell Programming and Scripting

running command more than twice in one second?

how do i do that? say i wanna run a check script but i want it to run at least twice in one second, what kinda script would that need? matter, this on a sunsolaris system. i would like it to run as many times as possible under one second but i guess i can live with 2 so does anyone know... (4 Replies)
Discussion started by: Terrible
4 Replies
Login or Register to Ask a Question