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

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?
LVL 10
oleberAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TintinCommented:
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.
0
oleberAuthor Commented:
This solution, is the one that I'm using:

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


0
ozoCommented:
can you set the users ssh_config file on the remote machine?
0
mrjoltcolaCommented:
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.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.