6

This question already has an answer here:

Very simple question, I'm new to Linux

I have a command run on startup (Elementary OS) command is:

/home/zachary/Documents/Server108/Server108.sh

When I turn my laptop on the command runs in the background, and this is great, but I can't issue a "Stop" command because the terminal never opens. So, my question is this;

How do I force the terminal to open, run the script and then stay open? Do I need to add a line to the .sh file, or add arguments to the startup command?

marked as duplicate by chili555, Jacob Vlijm, Eric Carvalho, Gunnar Hjalmarsson, muru command-line Apr 15 '16 at 19:52

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • You might be able to make a desktop file and set the Terminal= option to true. – TheWanderer Apr 13 '16 at 13:52
  • @JacobVlijm Yes, I'm using the default folders application that came with Elementary OS – Zachary Wight Apr 14 '16 at 4:29
  • @Zacharee1 How do I do this? – Zachary Wight Apr 14 '16 at 4:29
  • You could learn how to store the pid somewhere and kill that specific process. upstart systemd – earthmeLon Apr 15 '16 at 19:01
  • Just commenting, that there's a stackexchange community dedicated to Elementary OS here: elementaryos.stackexchange.com – userino Apr 15 '16 at 21:23
5

If you are using older GNOME you can add to startup something like this:

gnome-terminal --command "/path/myscript.sh"

Just edit your startup with gnome-session-properties GUI. It should be in System -> Properties menu or Applications –> Other –> Advanced Settings or press Alt+F2 and input it there. But apparently it was deprecated and it will not work on GNOME 3...

You can try adding into your folder ~/.config/autostart a file, let's say myscript.desktop with following content:

[Desktop Entry]
Type=Application
Exec=gnome-terminal --command "/path/myscript.sh"
Hidden=false
X-GNOME-Autostart-enabled=true
Name=Startup Script
Comment=

Above content is actually from my own system, created by mate-session-properties GUI and it works. Only updated it for GNOME. It actually might work on other environments, you'll just need to play with some details. Adding Terminal=true with Exec=/path/myscript.sh also works and with it you don't need to know the command to start your terminal.

On MATE it's easier, because it's still got that GUI. Commands are called mate-terminal and mate-session-properties. Here's how it looks on my MATE:

enter image description here

I'm not familiar with Elementary OS and you didn't say which desktop environment you are using (might be Pantheon which I've never worked on), but it should not be that different. You might need to figure out command to start your terminal and try running my-terminal --help or visit it's manpages to find proper parameter (or just try that much simpler Terminal=true solution).

And if for some reason Terminal=true doesn't work and you can't determine your terminal's commands, install XTerm:

sudo apt-get install xterm

Its command is xterm -e "/path/myscript.sh.

  • I tried adding the "gnome..." command to the startup menu, and tried adding "mate-terminal" to the script, neither opens the terminal. Am I doing something wrong? Maybe instead of trying to open the file with terminal, we could open terminal with a command to open the script already running? If that makes sense. So I turn it on, Terminal opens and automatically runs the command "sh /home/zachary/Documents/Server108/Server108.sh"? Because doing this manually provides the desired results? Is that possible? – Zachary Wight Apr 15 '16 at 13:11
  • You sure you have gnome-terminal installed? Maybe your OS have different default terminal? Open your terminal and input gnome-terminal --help :) I've never heard about opening terminal for already running process... And "sh /script.sh" won't work. I've tested my command and it works with startup and with Caja-Actions. Plus where are you entering that startup command? Ubuntu's got special GUI tool for startup programs. – GreggD Apr 15 '16 at 13:29
  • Updated my original answer, it should be more clear now. – GreggD Apr 15 '16 at 19:00

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