2

I am working with a c++ application which fires off a system command that launches a RSH sequence such as:

rsh MACHINE \"setenv DISPLAY machine:0;setenv TESTVALUE1 'test';setenv scenTime 0;setenv simName 'name';/devel/test/run.sh\"

The problem is that this code is csh specific and my shell is bash. So commands such as setenv variable value need to be export variable=value etc.

My question is there a way for rsh to be told to use a specific shell and not read the users profile or login files?

2

If you can, make the application use sh syntax instead of csh syntax. Csh is used by very few people this century and is often not installed by default. Sh is the standard. In fact for such a simple command you don't even need to care about the shell: you can just call the env program.

rsh MACHINE "env DISPLAY=machine:0 TESTVALUE1='test' scenTime=0 simName='name' /devel/test/run.sh"

If you can't change the application but your shell is bash, you can use a quirk of bash: when it is a non-interactive login shell and when its parent process is rshd or sshd, bash runs ~/.bashrc (which is also the file loaded by interactive non-login shells). You could put this in your .bashrc to define a setenv function to emulate csh:

if [[ $- != *i* ]]; then
  # Non-interactive shell
  setenv () {
    export "$1=$2"
  }
  return
fi
1

You can pass all your commands as argument to -c option.

Try:

rsh MACHINE csh -c '<your command>'
1
  • 1
    Beware of quoting though. Between the local shell, the remote bash and csh, that's a lot of nesting. Jan 7 '15 at 23:22
0

Simple answer: no you can't skip what's in /etc/profile and the shell that is specified in /etc/passwd is holy.

Imagine what would happen if someone tried to login using a system account with shell /bin/nologin and no password. It would be a disaster if the rshd (or any other program) would be allowed to overrule such basic security.

You have to go trough your users shell (whatever it is) and execute your command from there. If it is a single command: ask rsh to do just that for you.

rsh -l remoteuser host.example.com "mkdir testdir"

Source: Wikipedia

I assume you know the insecurities of rsh and that it is better to use ssh. Especially in automated processes, because you can make use of public key authentication. (So you don't need to disable any password or store an unencrypted password in your program.) You could even try to link your program against libssh2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.