Mongo shell stops responding to commands - bash

I am playing around a little with the mongo shell, but I have quite a tedious problem.
After I've switched to the database I'm working with using "use nameOfDatabase", and I issue my first command, the shell won't respond to any further commands after giving me the first response. I have to CTRL + C or CTRL + Z out of it, reconnect, switch to the db again and then issue another command to keep working.
Also, accessing commands from the history does not work since this just moves the cursor around the shell window (this also makes the shell stop responding).
Anyone have any ideas what might be wrong?

Ctrl+Z is for 'suspend'. Try Ctrl+D to exit the mongo prompt.

Related

What does cmd + up-arrow do in the terminal?

While using the terminal I accidentally typed Cmd + up-arrow and saw that my previous commands got highlighted. I was wondering if I accidentally discovered a cool hack for something (other than just highlighting previous commands), but I wasn't able to figure out what exactly the hot key is doing.

Bash script which works in the background, waiting for the key

I need script which works in the background, waiting for a key to be pressed. I have a script which works when terminal is on. When I try to use & - it's not working correctly. The script works in background but keypress doesn't do anything. When I try use nohup then I have error of read - bad descriptor.
Can someone help me?
When the terminal is on (and is selected, in case of a terminal emulator running on x server), the input (key strokes, etc.) is directed to the terminal; hence, your program works.
Now, consider an example: let's say that you created a script that runs on the background, and it is activated by pressing the letter "a". If pressing "a" triggered your script (with terminal closed), then the user would never be able to (for example) type the letter "a" in a word document or a web search without triggering the script!
Therefore, what you are looking for is a key bind, or a keyboard shortcut, which would bind a key (combination) such as ctl+j+k to launch the script you want.
In Linux, that can be done somewhat easily, see this for Ubuntu or this for Lubuntu.
Important: if your script needs to be root to work, then you generally will have to evoke it via gksu or gksudo, otherwise it will not run

Mac OSX bring the console window front most with shell command

Here I want to ask you to help to bring the console window top most with a shell command. Is it possible?
there was a script execution in my work environment, and will take about several minutes to complete, I will move to other work while running, it is better there are some tips to notify me when script completes run.
So I think bring the window top most is the most direct way.
Please tell me how to achieve this, I'm working on windows, new to MacOS.
Thanks,
Levi
I don't know how to bring the console window to the front, but if you're working in the terminal, you could do something like:
$ path/to/script ; tput bel
or
$ path/to/script ; say "script 1 is done"
Where path/to/script is whatever your usual method of loading the script is.
I recommend the first method, as it flashes the screen, makes a beeping noise, and causes the terminal icon to bounce up and down on my dock in OS X 10.10. The second might be better if you need to figure out which script is done from among a bunch of scripts. If you have coworkers who you don't want to disturb, you can change the preferences in terminal so that an alert only flashes the screen and doesn't also make a noise.
If you have access to the source code of the script, you can also add tput bel or say "command" to the last line of the script and you'll get the same behvaior.

Run script in background?

Simple question: Is there a way to run a script in the background with out terminal running?
More detail and background: I had an app that read an apps .log file and puled information from it, then provide information and statistics from the information in the log.
An update to the app changed the way the .log file was written and delete information and duplicates the log in a manner that i have been unable to predict.
the app that was designed to interface with the log was not coded to check for such changes. so when it attempts to gather information after the log change it stops working.
A "hack" has been devised to run a tail -f, then hexed the app to point at the new file.
(The "hack" works)
I would like to run the tail in the background so that the user doesn't interrupt it... breaking it...
-sorry for the (possibly) longer than needed description. BUt i figured a more detailed question would get me a precise answer.
Thanks in advance!
~¥oseph
The answer depends on if you need to be able to re-connect to the process after exiting the shell. If the process is non-interactive and can simply be left alone, then "nohup program &" should do the trick. But that won't let you continue to interact with the program after you've closed the shell.
If it's a interactive program, then your best bet is to use screen or one of the other terminal-multiplexers. You start "screen" which gives you a new shell, in this you start whatever program you want, the usual way, say "nano myfile.txt".
When you want to close the shell, but leave the program running, you press C-a d ('Detach') to detach from screen. it keeps running, but in the background, and will keep running even if you log out.
When you then later want to reconnect to screen you open a new shell and type "screen -r" (reconnect), this leaves you right where you where.
Screen also lets you run several different shells in a single terminal-window and is a neat tool overall. Check it out.

Can I Force MATLAB to quit after user presses Control-C?

I'm running MATLAB (command line version) from a shell script, and I'd like it to preserve shell behavior where if you press Ctrl-C it exits. But instead it wants to keep control of the terminal and I (or my poor users after me) have to type quit(1) to make it quit and tell the shell it failed.
You can't intercept Ctrl-C with a try/catch block... any other ideas? Anything I could do from the shell side to intercept the keystrokes before they get to MATLAB?
onCleanup seems like an option, but then I'd have to make the whole script thing into a function (it's already a dynamically generated try/catch block thing in a Makefile). But if that's the only thing that will work, then I'll do it...
Use onCleanup:
I wanted to do the same thing but after I read this thread I used onCleanup successfully. My problem was I had a server in Matlab that when pressing CTRL+C would keep listening on the port it was started on -> second run I would get a bind error.
You can try:
stty quit ^C
but I have no matlab to test it.

Resources