ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
3

roslaunch command does not run when put in crontab

asked 2012-05-07 16:01:48 -0600

clark gravatar image

I am setting crontab to let my computer to launch certain ros package when it starts up or reboots.

here is the content I put in crontab -e, @reboot bash -c '/home/user/launch.sh'

while the launch.sh file simply contains a single roslaunch command,

!/bin/bash

roslaunch socket_server socket.launch

The above .sh file confirms running fine in terminal, but every time when the pc (re)boots, the roslaunch commmand doesn't run as expected; and I can't even find any records in the sys log file.

Can anybody with experience on cron + ros configuring help?

thanks clark

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2012-05-07 17:06:26 -0600

joq gravatar image

You need to set up the ROS environment in the shell script.

edit flag offensive delete link more

Comments

Thanks for the quick help. You are totally right. After adding "source /opt/ros/electric/setup.bash" into the sh script, it works now

clark gravatar image clark  ( 2012-05-07 19:09:57 -0600 )edit
2

plus two points for other users who might be interested. First, the @reboot command need to be keyed in via crontab -e rather than sudo crontab -e; Secondly, using !/bin/bash rather !/bin/sh inside the shell script, or else commands like source won't work

clark gravatar image clark  ( 2012-05-07 19:36:34 -0600 )edit

I use crontab to execute "roscore" when the system is started, but crontab -e does not work, and sduo must be added to work normally.

startUp.bash

#!/bin/bash
source /opt/ros/noetic/setup.bash
roscore

sudo crontab -e

# m h  dom mon dow   commandi
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12)
# │ │ │ │ ┌───────────── day of week (0 - 6) (Sunday to Saturday;
# │ │ │ │ │                                       7 is also Sunday on some systems)
# │ │ │ │ │
# │ │ │ │ │
# * * * * *  command_to_execute

@reboot  bash /home/dodo/Desktop/startUp.bash >> /var/log/myjob.log 2>&1
cordic45 gravatar image cordic45  ( 2023-04-22 23:57:39 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2012-05-07 16:01:48 -0600

Seen: 2,341 times

Last updated: May 07 '12