Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have three scripts I need to run when I start up my Ubuntu machine, they start services I use in my development environment.

To do that, I manually open three terminals and type in the commands.

Is there any way to create a script that will open three terminals and execute one command in each of these? (Each command should be in a separate terminal window so I can see their output).

share|improve this question

5 Answers 5

up vote 33 down vote accepted
gnome-terminal -e command

or

xterm -e command

or

konsole -e command

Pretty much

terminal -e command

To make the terminal stay when the command exits:

In konsole there is a --noclose flag.

In xterm, there is a -hold flag.

In gnome-terminal, go to Edit -> Profile Preferences -> Title. Click the Command tab. Select Hold the terminal from the drop-down menu labelled When command exits. You should create a new profile for that and execute with

gnome-terminal --window-with-profile=NAMEOFTHEPROFILE -e command
share|improve this answer
1  
Hi, thanks! Is there any way so it doesn't close when the command is executed? –  Oscar Jun 2 '11 at 20:05
    
@Oscar Updated. It would be great if you told us what environment you use. –  nickguletskii Jun 2 '11 at 20:24
    
Hi, I am using Ubuntu 10.4 with the "basic" tools, i didn't "tuned" it by downloading anything –  Oscar Jun 4 '11 at 19:22
    
Thanks for your help, it is now working :) –  Oscar Jun 4 '11 at 19:42
    
@Oscar Then gnome-terminal it is. –  nickguletskii Jun 4 '11 at 19:42

Instead of hard-coding gnome-terminal, konsole, et cetera, use the Alternatives system. The program that executes the default terminal emulator is:

x-terminal-emulator

On my system, it opens a new instance of Konsole every time I execute this command.

Luckily, the terminals seems to support the -e option for executing a command (I verified it for konsole and gnome-terminal). Arguments after the command are passed to the invoked command. Bash refuses to stay open in my terminal, an additional script is needed to get a terminal:

#!/bin/sh
"$@"
exec "$SHELL"

If you've saved the previous script as /home/user/hacky and made it executable, you would run your scripts with:

x-terminal-emulator -e /home/user/hacky your-script optional arguments here

The full path is required and /home/user/hacky has to be executable.

My previous attempt to run a script in a new terminal window can be found in revision #2, it was before I realised arguments can be passed to x-terminal-emulator.

share|improve this answer
    
In this case, it won't help much as the asker wants to do something that isn't the same for all terminals. –  nickguletskii Jun 2 '11 at 20:36
    
Attempt #3: this one should keep the terminal open and run the program with optional arguments. –  Lekensteyn Jun 2 '11 at 21:06
    
Ty for that x-terminal-emulator knowledge. That was what i was looking for. –  prolink007 Oct 22 '12 at 19:55

Quite simply-

#!/bin/bash

/etc/init.d/ccpd status

This is enough for other commands that do not need to display anything in terminal. But here one has to see the status displayed.
So, it needs to run in a terminal window

#!/bin/bash

gnome-terminal -e "/etc/init.d/ccpd status"  --window-with-profile=NAMEOFTHEPROFILE

The other post intended [] to be a placeholder

Here "NAMEOFTHEPROFILE" is to be replaced with the name of the profile that "Holds the terminal when the command exits".

enter image description here

enter image description here

share|improve this answer
1  
@cipricus i believe [] was just placeholder –  Karthik T Jan 23 '13 at 9:37
    
got it. but i have to make the terminal not to close so fast. i guess that is also in the linked question –  cipricus Jan 23 '13 at 9:43
    
@cipricus have you tried the profile one? Just need to add --window-with-profile=NAMEOFTHEPROFILE to what I have given –  Karthik T Jan 23 '13 at 9:44
1  
@cipricus I would have to get back home to give better instructions, but the idea is to create a special profile with that option set, and use the name of the special profile in the place above. –  Karthik T Jan 23 '13 at 9:51
2  
@cipricus if that is enough for you, then that is ok. Profile is nothing more than a group of settings. You can setup the settings ONLY for use in your script, and not have to use it in all terminals. You can see Edit -> Profiles to see all the profiles you have, and you would add one there which was setup as explained in the post you linked –  Karthik T Jan 23 '13 at 15:39

Use the screen command and -d detach from an existing screen session, and reattach here -m force a new screen session -S create a named session instead of using the default name

share|improve this answer

Using gnome-terminal

You can not it is not possible

It takes a complicated script.

gnome-terminal -e command
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.