6

I am new in this platform. I have question about rc.local. I created a script to run automatically roscore and roslaunch rosbridge_server rosbridge_websocket.launch. This script name is auto and content of script is:

#!/bin/sh
cd $home
xterm -hold -e "roscore" &
xterm -hold -e "roslaunch rosbridge_server rosbridge_websocket.launch"
exit 0

I must run this script in rc.local. Created rc.local file is:

#!/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

Where am I do wrong ? I follow the solution with 9 step at How can I make "rc.local" run on startup? but it did not run.

derHugo
  • 3,376
  • 5
  • 34
  • 52

2 Answers2

3

Problem solved completely. Solution is given below.

Firstly create a script to you want to run in it. I want to run rosbridge_websocket automatically when computer starts up. My script name is auto and is located at home/username/auto.sh. Content of the script is:

#!/bin/bash

cd $home

source /opt/ros/indigo/setup.bash 

roslaunch rosbridge_server rosbridge_websocket.launch

exit 0

You must check that your script file is executable. To executable script file use the command: $ sudo chmod u+x /home/username/auto.sh

To do run this script in rc.local which is located at /etc/rc.local. It is created using gksudo gedit /etc/rc.local. Inside the rc.local is:

#!/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.

/home/username/auto.sh

exit 0

Finally, you must reboot your system using $ sudo reboot . When you starts up the computer your script is completely work.

1

rc.local is executed BEFORE a graphical user interface (i.e. X) is available. So executing xterm in your script auto.sh WILL fail. If you want an xterm to pop up at startup, you'll need to open it via Ubuntu's "Startup Applications". Running the script with root privileges will be a bit more evolved, as you'll have to set a NOPASSWD entry for it in the /etc/sudoers and make sure it's only editable by root.

starup applications

con-f-use
  • 19,041