How do I open a new window (shell) from command line in Linux? - linux

I'm working with a tool right now that requires me to putty to a remote host, login, run a series of commands to start an engine, open a new window (and login again) to start a different engine, then open a third window (and again, login) to actually use the tool (leaving the engines running in those first two windows). I'd like to write a shell script to automate the process so that I could just open one window, type "sh whatever.sh" and be off and running, without physically opening the new windows and logging in again. However, I can't find a command to get me from one window to the next. Any thoughts?

You can just background the first processes by adding an ampersand (&) to the command line or pressing Ctrl+Z when it is running (and then enter bg to let the process continue, more information about that with jobs).
If that's not enough, you can create virtual shells with screen or tmux.
If you've redirected X (i.e. you can access GUIs over ssh), you can also just start a new window by executing your favorite (GUI) console program, like xterm, konsole, gnome-terminal, etc.

Are you familiar with jobs on linux?
nohup whatever_1.sh &
nohup whatever_2.sh &
nohup whatever_3.sh &
Or perhaps screen would be of use here:
https://serverfault.com/questions/25301/job-control-and-ssh
See also, nohup:
http://en.wikipedia.org/wiki/Nohup

The bash command opens a Bourne-again shell (bash) session.

Try typing in "konsole". That should open a new bash window and set the focus to it.

On my Ubuntu 18 I just type the command:
gnome-terminal
and a new shell opens... I don't like the above answers because xterm and konsole most likely not already be installed.

Shell script on target machine cannot be aware of putty windows on client machine.
Consider using Screen : http://www.gnu.org/s/screen/ - it is clean and powerful way.

I think you need command line window then write:
$ xterm
# new window started
If you need python in new window:
$xterm python
#now a window will shown with python shell

Another nice option from Xfce's terminal:
xfce4-terminal

Related

open vim file in new unix terminal

How to open existing vim file from unix shell (bash) in new terminal (not in same/new tab of existing terminal) on local machine ?
Also is there any way to split file on new terminal (not in same/new tab of existing terminal) from inside vim ?
How to open a new terminal is platform dependent; This doesn't really have a whole lot to do with vim itself.
For example, if you're using GNOME you could do this by running gnome-terminal -e "vim $filename" & disown. Look up the documentation for the terminal emulator you're using to find out how to launch a new terminal and execute commands in it.
Another (IMHO much better) solution is to simply use GVim for situations like these, unless you have a very good reason to run vim in the terminal (if you're running this over ssh this won't work anyway, in that case you're better off using a terminal multiplexer like screen or tmux).
PS: bash isn't a terminal (emulator); bash is a shell. If you just run a new instance of bash it'll run in the same terminal, which is not what you want here.
Try this:
vim [your file]
If this isn't working for you, make sure you have it installed with:
sudo apt-get install vim
If you're already IN vim do
:edit [your file]

Linux (Raspbian) - Running script at login(auto) and keeping window in foreground for interaction

I have tried everything to make this work. login scripts, LXDE-pi autostart, cron task #reboot, init.d, and I cannot get my script running with a terminal window running in the foreground so that I can interact with it. I can get it to run but only in background. Is there any way I can get a script that simply runs: "python /home/pi/myscript.py" at startup and leaves the terminal window open with the script running for my keyboard inputs? I would rather not use the /dev/input/event if at all possible. Thanks
Simply running python /home/pi/myscript.py at startup will run your script without any terminal. So there is no window that can be kept open. The behavior you want can be achieved by starting an terminal application and let it execute your script.
e. g. using xterm:
xterm -e "python /home/pi/myscript.py"
or lxterminal:
lxterminal --command "python /home/pi/myscript.py"
I was missing a simple flag.. what I did was edit ~/.config/lxsession/LXDE-pi/autostart with
#lxterminal -e /home/pi/autoscript.sh
and in that file, I added
cd /home/pi/
python -i 2Trackmain.py
I wasn't using the -i flag, so every time I pressed Enter to move through the interactive py script, it exited the terminal, using -i will keep the window open for your interaction. And I only had to add the change directory part b/c the script called other scripts in the same directory.

Run a shell script in a new cygwin window

How can I run a shell script in a new cygwin window? The following just opens up the windows type of cmd window which is difficult to resize.
cygstart /cygdrive/c/cygwin/bin/bash ~/runmyapp.sh
Well, if you want to keep the window open after the script exits, you have to do something to make the shell that is executing the script not exit.
Here's an example that should work.
mintty bash -c "~/runfxtransact.sh; read -p \"Press enter to close this window.\"" &

Run emacs as separate process from terminal

When I run the emacs text editor the process does not return so I cannot use the terminal which is obviously the default behavior.
I cannot find the switch or command in the man but I know it is something very simple.
How can I run emacs as a separate process so I can continue to use the terminal without opening a second one?
You can start any program in the background by appending an ampersand to the command, emacs &.
There's a whole framework for working with backgrounded processes, see for example man jobs, disown, fg, bg, and try Ctrl-Z on a running process, which will suspend it and give you the terminal, allowing you to resume that process either in the foreground or background at your pleasure. Normally when your shell closes, all those programs will end, disown allows you to tell a program to keep running after you end your session.
The emacs --help command is giving you a tip:
--batch do not do interactive display; implies -q
So run emacs --batch (or maybe emacs --executesomecommand ).
If you have a desktop (or some X11 display) and want emacs to open an X11 windows and give you back a shell prompt, run it in the background (e.g. emacs &) as many commented.
And I find very useful to start programs (or shells) within emacs, e.g. with Emacs commands: M-x shell, or M-x compile (for make etc...), or M-x gdb for a debugger.
You usually start one single emacs at the beginning of a working day. You could use emacsclient (or set your EDITOR environment variable to it) for other editions using the same emacs.
I'd like to add that Windows does have an equivalent to *nix's & for starting programs in a separate process:
start /b emacs Main.hs

Terminal window closes after double clicking executable .sh file in Fedora Linux

I have to work on a project in Fedora Linux and I have to type the following very often:
player map1.cfg &
I figured out that I can create an executable .sh file and it contains this:
#!/bin/bash
player *.cfg &
However, when double click on the runmap.sh file it shows me 'Run in Terminal', 'Display', 'Cancel', and 'Run' and when I click 'Run in Terminal' a terminal window opens and closes immediately. If I just hit 'Run' then the .cfg opens but I need the Terminal window to run additional (Java) files.
How can I fix this problem?
Other information:
I use *.cfg because I want to copy and paste the .sh files into other folders that also contain .cfg files such as map2.cfg, map3.cfg, etc.
It's for a Player/Stage project.
When you run a script from the file manager, the shell that is started isn't interactive. The shell can only read the script file.
To open an interactive shell in addition to the files, you can exec the new shell at the end of the script, and use "Run in Terminal":
#!/bin/bash
player *.cfg &
exec /bin/bash
Well let's look at it this way.
When you run the command in a terminal, the command starts as a child process and is then sent to the background. Once the command finishes it terminates. During the time it is running in the background you can still issue commands because your parent process is the terminal window itself.
When you write a script that issues a command to run in the background it is started, spawns the command as a child to it and then closes because the script has finished.
These are a behavior of the OS and something that really shouldn't change. Essentially what you are therefore asking for is a way for it to run the command quickly for yourself yet still leave a command terminal for you to work with?
1) Why is typing the command such a hassle? Bash and other terminals have a history function for this very reason.
2) Why don't you just call the mini script you wrote from a terminal window whenever you need to call the commands. If you put the script in a folder on your $PATH variable it will be available to you in the terminal at any location.

Resources