Ask Your Question

Cannot set env variables when ssh a network machine [closed]

asked 2014-07-11 09:02:38 -0600

Luis Ruiz gravatar image

updated 2016-03-18 07:32:44 -0600

I am trying to set up a network configuration between two machines. I already did all the steps mentioned in the ROS tutorials. This is my setup:

In PC1:

export ROS_MASTER_URI=https://${PC1_hostname}:11311
rosrun <package> <node>

In PC2:

export ROS_IP="$(ifconfig | perl -nle'/dr:(10\.85\.167\.\S+)/ && print $1')"
export ROS_HOSTNAME="<PC2_hostname>"
export ROS_MASTER_URI=https://${PC1_hostname}:11311
rosrun <package> <node>

I can trasmit data back and forth between the two machines using ROS.

Now, I want to start PC2 from PC1 using a launch file. ROS indeed get the connection from PC1 to PC2, but then the program fails when trying to run the node. I found that the error is because ROS is ssh-ing into PC2, and ssh does not allow to set environment variables, which means ROS was never sourced and there isn't any environment variables. My file is right since if I run the script locally it works.

I found this on the web, I tried some of the solutions with no success.

ssh environment variables

How to allow environment variables to be set when ssh into an external PC?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Luis Ruiz
close date 2014-07-11 21:13:26.486849


Environment variables must be set when you ssh into another machine.

McMurdo gravatar image McMurdo  ( 2014-07-11 09:28:12 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2014-07-11 17:49:09 -0600

ahendrix gravatar image

In the machine tag in your launch file, you need to specify the env-loader parameter. See:

Note that the requirements for the env-loader script are fairly strict. It should:

  • Be executable. ( run chmod a+x on it, and make sure the first line is #!/bin/bash )
  • Source ROS.
  • Set your other environment variables, such as ROS_MASTER_URI and ROS_IP
  • The last line MUST be exec "$@"

If you're still having trouble, please EDIT your question to include your launch file and the exact console output you get from trying launch it.

edit flag offensive delete link more


This works!!! I had to put `exec "$@"` at the end of the `` file.

Luis Ruiz gravatar image Luis Ruiz  ( 2014-07-11 21:10:19 -0600 )edit

Question Tools

1 follower


Asked: 2014-07-11 09:02:38 -0600

Seen: 226 times

Last updated: Mar 18 '16