Ubuntu – How to run script in rc.local

scriptsstartup

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.

Best Answer

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.

Related Question