how to make rsh (unix utility) source my .profile (korn shell)

how to make rsh (unix utility) source my .profile (korn shell)

Post by kumar.sa.. » Fri, 05 Nov 2004 16:04:59



Hi,
I recently switched over to ksh (using csh earlier). The rsh
command used to read my .cshrc when i executed the following
command
rsh <mach name> <command>

Once I swtiched to ksh, rsh does not read my .profile .

How can I make rsh read my .profile file or some other file ?

Any help on this will be appreciated. I am completely stuck
on this one.

Thanks,
Sandeep Kumar

 
 
 

how to make rsh (unix utility) source my .profile (korn shell)

Post by Laurenz Alb » Fri, 05 Nov 2004 18:54:55



> I recently switched over to ksh (using csh earlier). The rsh
> command used to read my .cshrc when i executed the following
> command
> rsh <mach name> <command>

> Once I swtiched to ksh, rsh does not read my .profile .

> How can I make rsh read my .profile file or some other file ?

.profile is only sourced by login shells, and the shell spawned by rshd
seems to be no login shell.

Maybe you can use the ENV environment variable in ksh: if this variable
is set and points to a file, that file is sourced by every ksh.

You could create a file /etc/kshrc that contains something like:
if [ -f $HOME/.kshrc ]; then
   . $HOME/.kshrc
fi

Then set the ENV environment variable to /etc/kshrc in a place where
anvironment variables valid for ALL processes are set (this varies from
platform to platform, consult your documentation).

Then, in the .kshrc in the home directory of the user, you can add the
commands you want.

Yours,
Laurenz Albe

 
 
 

how to make rsh (unix utility) source my .profile (korn shell)

Post by Sandeep Kuma » Fri, 05 Nov 2004 20:41:40


Hi Laurenz,
Your suggestions doesn't seem to work.

To verify the changes, I did the following. Created a executable file
named "sandeep" with the following contents (the env variable INPUTRC is
defined in my system's default kshrc)
--------------------------------------------------------
print $LD_LIBRARY_PATH
print $INPUTRC
ls
--------------------------------------------------------

and then did
        rsh <some mach name> ./sandy

Both the print statements output "" (blank). Seems like that the system
wide profile file is also not sourced by the ksh.

Any other pointers or suggestions ?

Thanks,
Sandeep Kumar

On Thu, 4 Nov 2004 09:54:55 +0000 (UTC)



> > I recently switched over to ksh (using csh earlier). The rsh
> > command used to read my .cshrc when i executed the following
> > command
> > rsh <mach name> <command>

> > Once I swtiched to ksh, rsh does not read my .profile .

> > How can I make rsh read my .profile file or some other file ?

> .profile is only sourced by login shells, and the shell spawned by
> rshd seems to be no login shell.

> Maybe you can use the ENV environment variable in ksh: if this
> variable is set and points to a file, that file is sourced by every
> ksh.

> You could create a file /etc/kshrc that contains something like:
> if [ -f $HOME/.kshrc ]; then
>    . $HOME/.kshrc
> fi

> Then set the ENV environment variable to /etc/kshrc in a place where
> anvironment variables valid for ALL processes are set (this varies
> from platform to platform, consult your documentation).

> Then, in the .kshrc in the home directory of the user, you can add the
> commands you want.

> Yours,
> Laurenz Albe

--
"I am Troy McClure of Borg. You may remember me from such films as
'Assimilation Day', and 'Honey, I Assimilated The Kids' ."
 
 
 

how to make rsh (unix utility) source my .profile (korn shell)

Post by Stephane CHAZELA » Fri, 05 Nov 2004 22:18:06



Quote:> Hi,
> I recently switched over to ksh (using csh earlier). The rsh
> command used to read my .cshrc when i executed the following
> command
> rsh <mach name> <command>

> Once I swtiched to ksh, rsh does not read my .profile .

[...]

Yes, .profile is not the shell customization file, it's the
login session profile. rsh invokes a shell remotely, it does not
start a login session. If you wan't to have the same environment
as the one you would get when logged on that remote machine,
then you need to explicitely source the session profile:

rsh <mach name> '[ -r /etc/profile ] && . /etc/profile
                 [ -r ~/.profile ] && . ~/.profile
                 some-command'

But be sure your .profile doesn't assume it is run only on
terminals by login shell (for instance, the "stty", banners
should be put in:

if [ -t 1 ] && [ -t 0 ]; then
  case $- in
   *i*) stty ...
        printf '%s\n' "Wellcome...";;
  esac
esac

--
Stephane

 
 
 

how to make rsh (unix utility) source my .profile (korn shell)

Post by Laurenz Alb » Fri, 05 Nov 2004 22:29:07



> To verify the changes, I did the following. Created a executable file
> named "sandeep" with the following contents (the env variable INPUTRC is
> defined in my system's default kshrc)
> --------------------------------------------------------
> print $LD_LIBRARY_PATH
> print $INPUTRC
> ls
> --------------------------------------------------------

> and then did
>        rsh <some mach name> ./sandy

> Both the print statements output "" (blank). Seems like that the system
> wide profile file is also not sourced by the ksh.

Put the following in your ./sandy
echo $ENV

If /etc/kshrc is not printed when you invoke via rsh, you didn't set
the environment variable in the appropriate place.

What are the 'system's default kshrc' and the 'system wide profile'
you mention in your post?

Your problem might depend on the operating system you are using.
What does 'uname -a' tell you?

Yours,
Laurenz Albe

 
 
 

how to make rsh (unix utility) source my .profile (korn shell)

Post by javie » Fri, 19 Nov 2004 09:31:14


ENV only works for login sessions. You need to create a file with all the
environment variables for that particular user. Then, source that file from
your scripts. The best source of env variables is a login session.

1) login: as <user>
2) run:  set  > env.<user>
3) edit: env.<user> :
  * Prepend "export" to every line in order for the variables to be part of
the environment.
  * Make sure there are no spaces in the variable definitions if you find
any, then quote the values of the variables
  * Also, note that variables like SECONDS, PWD, etc. should be removed (I
never include IFS, it makes life easier)

 If any of .profile, $ENV, /etc/profile, /etc/profile.local or other files
sourced by them change, then you will have to re-create the file env.<user>
from a login session.

 Once env.<user> has been edited you can rsh, remsh, "su <user> -c
/.../script" or whatever you do (a scheduler like Tivoli/Maestro does a "su
<user>"as root --no login, hence you need to source the env file).

 The sintax to source the env.<user> within your script "sandy" is::
 .  /path/to/env.<user>
^
|
\
(dot)

 Each user needs it's own env.<user> file

 I have used this method in my last job (EMEA data centre running 24/7
operations for all entities) for about 4 years. Hence, it is well tested and
safe. Try it and see if it works for you.

 I hope this helps.


> Hi Laurenz,
> Your suggestions doesn't seem to work.

> To verify the changes, I did the following. Created a executable file
> named "sandeep" with the following contents (the env variable INPUTRC is
> defined in my system's default kshrc)
> --------------------------------------------------------
> print $LD_LIBRARY_PATH
> print $INPUTRC
> ls
> --------------------------------------------------------

> and then did
> rsh <some mach name> ./sandy

> Both the print statements output "" (blank). Seems like that the system
> wide profile file is also not sourced by the ksh.

> Any other pointers or suggestions ?

> Thanks,
> Sandeep Kumar

> On Thu, 4 Nov 2004 09:54:55 +0000 (UTC)


>> > I recently switched over to ksh (using csh earlier). The rsh
>> > command used to read my .cshrc when i executed the following
>> > command
>> > rsh <mach name> <command>

>> > Once I swtiched to ksh, rsh does not read my .profile .

>> > How can I make rsh read my .profile file or some other file ?

>> .profile is only sourced by login shells, and the shell spawned by
>> rshd seems to be no login shell.

>> Maybe you can use the ENV environment variable in ksh: if this
>> variable is set and points to a file, that file is sourced by every
>> ksh.

>> You could create a file /etc/kshrc that contains something like:
>> if [ -f $HOME/.kshrc ]; then
>>    . $HOME/.kshrc
>> fi

>> Then set the ENV environment variable to /etc/kshrc in a place where
>> anvironment variables valid for ALL processes are set (this varies
>> from platform to platform, consult your documentation).

>> Then, in the .kshrc in the home directory of the user, you can add the
>> commands you want.

>> Yours,
>> Laurenz Albe

> --
> "I am Troy McClure of Borg. You may remember me from such films as
> 'Assimilation Day', and 'Honey, I Assimilated The Kids' ."