0

I have a question about rc.local. I created a script auto.sh and it includes:

#!/bin/sh
cd $home
source /opt/ros/indigo/setup.bash 
xterm -hold -e "/opt/ros/indigo/bin/roscore" &
xterm -hold -e "/opt/ros/indigo/bin/roslaunch rosbridge_server rosbridge_websocket.launch"
exit 0

My purpose is run to this script automatically using rc.local. rc.local file located at:

/etc/init.d/rc.local

rc.local file includes the code :

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

sudo ./auto.sh
sh '/home/moguztas/auto.sh'

exit 0

This code is executable. I followed the steps at How can I make "rc.local" run on startup? .

But when I check the code using:

sudo /etc/init.d/rc.local start

it gives a error in terminal as given below:

./auto.sh: 4: ./auto.sh: source: not found

Also, in XTerm terminal errors are given like : error1 error2

Could you tell what is my problem ?

  • 4
    sh on Ubuntu is the dash shell, not bash. It has no such command as source – Zanna Apr 26 '17 at 10:13
  • The error states it cannot find/import the module roslaunch. That should set you on right track ? –  Apr 26 '17 at 11:17
  • NO, it states that it can not find the command source .. – Soren A Apr 26 '17 at 11:21
  • @Soren: I was referring to the error2 question. Zanna already addressed the source-question. But for completeness, the command: sh '/home/moguztas/auto.sh' should be changed to: bash '/home/moguztas/auto.sh' –  Apr 26 '17 at 11:48

1 Answers1

3
  1. You're invoking /bin/sh, which, on Ubuntu, is a much simpler shell than /bin/bash, and lacks the source command.

  2. At the time rc.local runs, is /opt/ros/indigo/ mounted? If it is your encrypted HOME directory, it won't exist until you log in.

  3. At the time rc.local runs, the X server has not yet started, so running an xterm won't work.

waltinator
  • 36,399
  • 1
    Thank you for your attention. I change /bin/sh with /bin/bash, my problem is solved. But I have another problem now. rc.local does not automatically when computer start up. What must I do for this ? – moguztas Apr 26 '17 at 21:18
  • Ask a separate question, or reread my answer. – waltinator Apr 27 '17 at 03:41