Skip to content

UssCmd environments variables missing due to profile files not loading in ChannelExec #604

Description

@frankgiordano

Description

When executing commands via UssCmd.issueCommand(), environment variables defined in /etc/profile or ~/.profile (such as PATH or STEPLIB) are not loaded. This causes mainframe commands dependent on these profiles to fail with file-not-found or execution environment errors.

Cause

The ManagedChannel class opens a JSch ChannelExec ("exec") connection. By default, SSH daemons treat exec channels as non-interactive, bypassing the execution of standard shell login profiles.

Proposed Solution – Update Documentation

Add guidance to the Javadoc and README.md explaining that SSH exec channels do not automatically load the user's login environment. Document how to mitigate this behavior by prepending the appropriate shell profile commands to the command string before execution.

Example:

// The SSH "exec" channel does not load the user's shell profile.
// Source the profile before executing the requested command.
command = "[ -f /etc/profile ] && . /etc/profile 2>/dev/null; " +
          "[ -f ~/.profile ] && . ~/.profile 2>/dev/null; " +
          command;

This approach ensures that environment variables, aliases, and other shell configuration settings defined in the user's profile are available during command execution.

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions