0

I'm new to Linux, so not sure how to do what I want.

I have my_script.sh (executable, of course) like this:

#!/usr/bin/env bash
mate-terminal -e "bash -c 'cd /home/my_user/ruby_projects/my_app/';'rails s';exec $SHELL"

NOTE: This script should open terminal, change current directory to the given one in that terminal, start rails application without closing terminal. All these things should be done after booting of the system automatically (now I run this script manually). Script contains a few similar comands, so a few terminals should be opened.

If I open terminal, go to the directory of the script, run ./my_script.sh - everything works perfectly and exactly how I want it to work, but every time I boot I have to do this manually.

So I went to Control center -> Startup Applications -> Add -> browsed my shell script, gave name -> Add

After that I restarted system and... :( Everything what I see is a few blinks on the screen (that is the opening and closing of mate-terminals) - everything happens so quickly that I can not see what it shows (however, all terminals should remain opened!). And, of course, no rails apps are started. All terminals are closed. How to fix this?

Update: at first my thought was that not all processes that were needed for rails apps started and that is why terminals simply closed, so I tried ty add sleep 10 for the script to wait till everything boots properly, but that changed nothing - blinking was just delayed by 10 seconds.

  • Where are you trying to get this to run? Upon reboots of the system? That's a special situation that you cannot simply add scripts like this and expect them to run. Especially with X GUI's such as mate-terminal. Please update your Q and describe what you're really trying to accomplish here. – slm Nov 30 '14 at 14:20
  • It's already written what I'm trying to accomplish. I've made it bold for you. Main task - run script automatically after each system boot, but not manually. – kovpack Nov 30 '14 at 14:49
  • This can't really be done "at boot". Perhaps you mean when your user logs into the Desktop ? If that "Control Center" is similar to the Ubuntu one, this question (and second answer) is relevant. And what will be the value of $SHELL here ? Because when I run bash -c "echo $SHELL" I get zsh :) – Leiaz Nov 30 '14 at 14:56
  • (What I meant is, is "$SHELL" defined when the script is ran by this "autostart"). – Leiaz Nov 30 '14 at 15:07
  • I've found in some answers that $SHELL keeps terminal opened when all previous commands finished executing. And it works this way, when I run script manually. I've tried sleep 10 - but it did not help. Maybe, something is really wrong with $SHELL. – kovpack Nov 30 '14 at 15:08
1

After a day of struggling I finally ended up with even better thing I needed:

#!/bin/bash

# Adds RVM to needed paths to start servers with needed Ruby version
PATH=$PATH:$HOME/.rvm/bin
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

# I need this server to run in background
startLocalRedmineServer()(
cd /home/adminuser/ruby_projects/redmine/
rails server webrick -e production --port 3001
)

# I need this to be done in background also
proxyLocalRedmineServer()(
proxylocal 3001 --host=mylocalredmine
)

# This thing should open mate-terminal, run start server, so that I can see real time logs, and stay on the screen in case I need it to be restarted
startOtherLocalServer()(
mate-terminal -e "bash -c 'cd /home/adminuser/ruby_projects/project_abc/';'rails s';'exec /bin/bash'"
)

# This thing should open mate-terminal and start proxying + remain opened
proxyOther()(
mate-terminal -e "bash -c 'proxylocal 3000 --host=projectabc'; 'exec /bin/bash'"
)

startLocalRedmineServer &
proxyLocalRedmineServer &
startOtherLocalServer &
proxyOther &
wait

This scripts is added for startup as I've written above in the question. After system starts this script adds new paths, which were lacking, and then starts 4 separate subprocesses. Two of them - that is Redmine server and its proxy - work in background (I do not need to stop them or change there anything). Two other functions open separate terminals, start local rails server and proxy it, so that I can stop it or restart when needed.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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