Issue
I am working with Ubuntu 16.04 and I have two shell scripts:
- run_roscore.sh : This one fires up a roscore in one terminal.
- run_detection_node.sh : This one starts an object detection node in another terminal and should start up once run_roscore.sh has initialized the roscore.
I need both the scripts to execute as soon as the system boots up.
I made both scripts executable and then added the following command to cron:
@reboot /path/to/run_roscore.sh; /path/to/run_detection_node.sh
, but it is not running.
I have also tried adding both scripts to the Startup Applications using this command for roscore: sh /path/to/run_roscore.sh
and following command for detection node: sh /path/to/run_detection_node.sh
. And it still does not work.
How do I get these scripts to run?
EDIT: I used the following command to see the system log for the CRON process: grep CRON /var/log/syslog
and got the following output:
CRON[570]: (CRON) info (No MTA installed, discarding output)
.
So I installed MTA and then systemlog shows:
CRON[597]: (nvidia) CMD (/path/to/run_roscore.sh; /path/to/run_detection_node.sh)
I am still not able to see the output (which is supposed to be a camera stream with detections, as I see it when I run the scripts directly in a terminal). How should I proceed?
Solution
Since I got this working eventually, I am gonna answer my own question here.
I did the following steps to get the script running from startup:
- Changed the type of the script from shell to bash (extension
.bash
). - Changed the shebang statement to be
#!/bin/bash
. - In Startup Applications, give the command
bash path/to/script
to run the script.
Basically when I changed the shell type from sh
to bash
, the script starts running as soon as the system boots up.
Note, in case this helps someone: My intention to have run_roscore.bash
as a separate script was to run roscore as a background process. One can run it directly from a single script (which is also running the detection node) by having roscore&
as a command before the rosnode starts. This command will fire up the master as a background process and leave the same terminal open for following commands to be executed.
Answered By - Rahul Bohare