I am working with Ubuntu 16.04 and I have two shell scripts:
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
@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?
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:
.bash
). #!/bin/bash
. 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.
If you could install immortal you could use the require
option to start in sequence your services, for example, this is could be the run config for /etc/immortal/script1.yml
:
cmd: /path/to/script1
log:
file: /var/log/script1.log
wait: 1
require:
- script2
And for /etc/immortal/script2.yml
cmd: /path/to/script2
log:
file: /var/log/script2.log
What this will do it will try to start both scripts on boot time, the first one script1
will wait 1 second before starting and also wait for script2
to be up and running, see more about the wait
and require
option here: https://immortal.run/post/immortal/
Based on your operating system you will need to configure/setup immortaldir , her is how to do it for Linux: https://immortal.run/post/how-to-install/
Going more deep in the topic of supervisors there are more alternatives here you could find some: https://en.wikipedia.org/wiki/Process_supervision
If you want to make sure that "Roscore" (whatever it is) gets started when your Ubuntu starts up then you should start it as a service (not via cron). See this question/answer .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.