rsh command

we want to execute remote script via rsh (we just only should use rsh except others),but rsh command can not set environment variable for specify user, then scripts can not be executed correctly,anyone knows how to fix this problem? thanks.

Put the environment variable assignment in the command to execute...

rsh remote-host "FOO=bar do-thing"

Because the command required many environment variables which are defined in the specify user's profile:.bash_profile, we create a executed scripts.First in scripts, we want to execute .bash_profile to set evnironment, secondly, to run the program. The scripts looks like the following

    #!/sbin/sh
      .   .bash_profile   or . .profile           # set the environment variable
      ...
      do-something

The rsh can not run the script normally.

Why have you got "#!/sbin/sh" ?

What is it you are wanting? You can include environment variables in the command as I've shown. Alternatively have the variables in the user's .profile on the other machine. I notice you did not use "$HOME/.profile".

"#!/sbin/sh" told the system the current shell is :/sbin/sh.

we do not want to put all environment variables in the rsh command line as you show. So we edit a shell script named shell-script on the remote host, this script include the contents I've described:

    HOME=/data/users/osa
   .  $HOME/.profile or  .  $HOME/.bash_profille
   ...
   nohup $HOME/bin/my_program
 

on the local host, we excute the above script on the remote-host likes this:
rsh remote-host -l remote-user shell-script.

Why do you need to set up HOME in the script if the goal is to run the user's .profile?

HOME is used in user's .profile. Here redefined this variable for confirming. there is nothing to do with this, I can comment it. What I want to do is make sure the path of .profile is correct and can be excuted .

Do you want to check that exists? Normally it's "/bin/sh".

I checked it, actually being my fault, it's /bin/sh.