Set a remote "environment variables" with "Net::SSH::Perl"

Posted on 2009-05-25
Medium Priority
Last Modified: 2012-05-07
I'm trying to run some commands remotely by ssh.

I need to set some environment variables in the remote machine for this connection.

How do I do that?
Question by:oleber
LVL 48

Expert Comment

ID: 24465046
Say you need to set the environment variable "VAR" to a value, you can do:

$ssh->cmd("VAR=foo command");

Note that you can not permanently set environment variables via this method.
LVL 10

Author Comment

ID: 24465119
This solution, is the one that I'm using:

I will run a set of commands, +- 100 commands. I prefer set the variables permanently.

LVL 85

Expert Comment

ID: 24465226
can you set the users ssh_config file on the remote machine?
LVL 40

Accepted Solution

mrjoltcola earned 2000 total points
ID: 24467806
I typically create a profile or environment script on the remote machine and source it as the first command, or simpler, create a self-contained script on the remote that sources or sets the environment variables.

If you are using bash on the remote machine, you can add them into .bashrc which will get sourced via a non-interactive shell, as in this case.


Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question