Discussion:
ssh, non-interactive, ksh shell environment
(too old to reply)
m***@juno.com
2007-06-07 15:46:05 UTC
Permalink
I cannot figure out how to get the environment setup correctly for the
connection I'm making with PuTTY's plink application. With putty, I
saved a session from an ssh connection; it includes the username to
connect as and the path to the private key file to use for
authentication. So when I connect interactively with putty, using the
saved session, I don't need to provide a username or password, I'm
automatically connected as the saved user and the expected environment
variables and values exist. The shell is ksh. When I connect with
plink, non-interactively, using the same "saved session", I just need
to run one command (a ksh script). It is still connecting as the
saved user (at least $HOME is the expected value and a plink message
says "Using username abc".) but the enironment is not set as it was
with the putty connection; which means the script fails.

The environment settings that I need are set in the user's .profile
file, so I think the "saved session" might be treated as a login
invocation of ksh, at least through putty. But obviously .profile is
not being sourced when I connect with plink. Any ideas on what
startup files are being sourced when I connect with plink this way?
What files could I create or edit so that the saved username
user's .profile is sourced when I connect with plink? Or do I need to
duplicate (or move) the settings I care about to a more global startup
file?
Joachim Schmitz
2007-06-07 17:00:56 UTC
Permalink
Post by m***@juno.com
I cannot figure out how to get the environment setup correctly for the
connection I'm making with PuTTY's plink application. With putty, I
saved a session from an ssh connection; it includes the username to
connect as and the path to the private key file to use for
authentication. So when I connect interactively with putty, using the
saved session, I don't need to provide a username or password, I'm
automatically connected as the saved user and the expected environment
variables and values exist. The shell is ksh. When I connect with
plink, non-interactively, using the same "saved session", I just need
to run one command (a ksh script). It is still connecting as the
saved user (at least $HOME is the expected value and a plink message
says "Using username abc".) but the enironment is not set as it was
with the putty connection; which means the script fails.
The environment settings that I need are set in the user's .profile
file, so I think the "saved session" might be treated as a login
invocation of ksh, at least through putty. But obviously .profile is
not being sourced when I connect with plink. Any ideas on what
startup files are being sourced when I connect with plink this way?
What files could I create or edit so that the saved username
user's .profile is sourced when I connect with plink? Or do I need to
duplicate (or move) the settings I care about to a more global startup
file?
I think non-login shells don't go throug any startup files, neither local
like .profile nor global like /etc/profile.
Korn-Shells (every, not just the initial login shell) source in a file named
in $ENV, maybe you can cause plink to have that variable passed to the shell
it starts?

Bye, Jojo
Joachim Schmitz
2007-06-07 17:08:14 UTC
Permalink
Post by m***@juno.com
I cannot figure out how to get the environment setup correctly for the
connection I'm making with PuTTY's plink application. With putty, I
saved a session from an ssh connection; it includes the username to
connect as and the path to the private key file to use for
authentication. So when I connect interactively with putty, using the
saved session, I don't need to provide a username or password, I'm
automatically connected as the saved user and the expected environment
variables and values exist. The shell is ksh. When I connect with
plink, non-interactively, using the same "saved session", I just need
to run one command (a ksh script). It is still connecting as the
Can't you source in .profile inside that script?
Post by m***@juno.com
saved user (at least $HOME is the expected value and a plink message
says "Using username abc".) but the enironment is not set as it was
with the putty connection; which means the script fails.
The environment settings that I need are set in the user's .profile
file, so I think the "saved session" might be treated as a login
invocation of ksh, at least through putty. But obviously .profile is
not being sourced when I connect with plink. Any ideas on what
startup files are being sourced when I connect with plink this way?
What files could I create or edit so that the saved username
user's .profile is sourced when I connect with plink? Or do I need to
duplicate (or move) the settings I care about to a more global startup
file?
Or get plink to do 2 commands ". ~/.profile; my_ksh_script"

Bye, Jojo
m***@juno.com
2007-06-07 20:21:17 UTC
Permalink
Post by Joachim Schmitz
Post by m***@juno.com
connection I'm making with PuTTY's plink application. With putty, I
saved a session from an ssh connection; it includes the username to
connect as and the path to the private key file to use for
authentication. So when I connect interactively with putty, using the
saved session, I don't need to provide a username or password, I'm
automatically connected as the saved user and the expected environment
variables and values exist. The shell is ksh. When I connect with
plink, non-interactively, using the same "saved session", I just need
to run one command (a ksh script). It is still connecting as the
Can't you source in .profile inside that script?
Post by m***@juno.com
saved user (at least $HOME is the expected value and a plink message
says "Using username abc".) but the enironment is not set as it was
with the putty connection; which means the script fails.
The environment settings that I need are set in the user's .profile
file, so I think the "saved session" might be treated as a login
invocation of ksh, at least through putty. But obviously .profile is
not being sourced when I connect with plink. Any ideas on what
startup files are being sourced when I connect with plink this way?
What files could I create or edit so that the saved username
user's .profile is sourced when I connect with plink? Or do I need to
duplicate (or move) the settings I care about to a more global startup
file?
Or get plink to do 2 commands ". ~/.profile; my_ksh_script"
Bye, Jojo
Yes, I was hoping there was a simple option I didn't know about. What
you suggested works, ". ~/.profile; script.ksh". Thank you. Since I
don't own the script development, I'll send "~/.profile; ..." - though
I think your first suggestion, to include it in the script, is a
better practice if the intention is to allow other systems to run it;
that way the script is not assuming a certain type of shell
invocation. Thanks again.
Glenn Jackman
2007-06-07 20:28:25 UTC
Permalink
At 2007-06-07 04:21PM, "***@juno.com" wrote:
[...]
Post by m***@juno.com
Yes, I was hoping there was a simple option I didn't know about. What
you suggested works, ". ~/.profile; script.ksh". Thank you. Since I
don't own the script development, I'll send "~/.profile; ..." - though
[...]

Careful: the dot is the critical part -- it's the ksh "source" command.

Do: ". ~/.profile; ..."
NOT: "~/.profile; ..."
--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry
Loading...