简体   繁体   中英

Set environment variables within SSH Session

I have a situation where I have a host machine where I need certain applications installed with side by side versions. Obviously only one can get added to the exports to run by default. As an example we might say it's Python 2.7, Python 3.5, & Python 3.7.

I need to be able to establish an SSH connection to the host, where each connection can set the correct path for the specific version that is required. Is there an easy way to do this. The key here is that each connection cannot affect either the host itself or other connections. Someone running on the host itself shouldn't break because the path was updated by a remote connection.

For the case of multiple (python and other) hierarchies, and assuming that the tools are invokes by the tool name (python ...), prepending the preferred path to the system path will provide a way to specify per-instance tool setting, without having side effect between jobs.

ssh ... 'PATH=/path/to/python3.1/bin:$PATH command'

Depending on the number of tools, and complexity of the setup, you might want to implement this as a wrapper

ssh ... '/path/to/run-with-pkgs python-3.2 pkg2 -- command'

With the pkg-setup script source various config script. Something along the lines of:

run-with-pkgs

#! /bin/bash
while [ $# -gt 0 ] && [ "$1" != "--" ] ; do
   source "/path/to/setup.d/$1.sh"
   shift
done
if [ "$1" = "--" ] ; then
    shift
    exec "$@"
fi

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM