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.

4
  • If your using Ubuntu 16.04, why not use systemd service instead? Apr 26, 2017 at 8:02
  • No need of sudo auto.sh and did you try running auto.sh script manually with ./auto.sh or sh auto.sh?
    – d a i s y
    Apr 26, 2017 at 8:04
  • script is manually execute with ./auto.sh . I'm using Ubuntu 14.04
    – moguztas
    Apr 26, 2017 at 8:18
  • @moguztas this does not seems a useful question about rc.local. "The instructions didn't work" because you made a mistake or a false assumption. Those instructions work. We are not psychic and cannot determine which mistake you made with the data provided. Consider rephrasing the question to 'learning how to debug' or 'startup and login process'.
    – user535733
    Apr 26, 2017 at 11:41

2 Answers 2

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

2
  • As I said I followed the solution with 9 steps in askubuntu.com/questions/9853/…
    – moguztas
    Apr 26, 2017 at 8:21
  • 1
    Then, in rc.local, pipe the output to a file like so: /path/to/auto.sh > /home/user/autosh.log and see if there are any errors that might give you a clue. Also see my edit!
    – con-f-use
    Apr 26, 2017 at 9:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .