rsh to host and run command as another user

I have a script, in which I rsh to a host and run a command based on a
variable. However, I am having issues with this portion of the
script. Would appreciate any ideas.


example
FOOHOME=/usr/local/foo/
I want to rsh to machine b from machine a and run a command as user
foo

from machine a
#rsh -n machineb "su - foo - c '$FOOHOME/bin/command'"

The above does not work and I am wondering how to get this to run.
littlehelphere [ Mi, 09 Januar 2008 23:10 ] [ ID #1903325 ]

Re: rsh to host and run command as another user

littlehelphere [at] gmail.com wrote:

> I have a script, in which I rsh to a host and run a command based on a
> variable. However, I am having issues with this portion of the
> script. Would appreciate any ideas.
>
>
> example
> FOOHOME=/usr/local/foo/
> I want to rsh to machine b from machine a and run a command as user
> foo
>
> from machine a
> #rsh -n machineb "su - foo - c '$FOOHOME/bin/command'"

Can't you just use "-l foo" in the rsh command line?
PK [ Mi, 09 Januar 2008 23:29 ] [ ID #1903326 ]

Re: rsh to host and run command as another user

On Jan 9, 5:29 pm, pk <p... [at] pk.pk> wrote:
> littlehelph... [at] gmail.com wrote:
> > I have a script, in which I rsh to a host and run a command based on a
> > variable. However, I am having issues with this portion of the
> > script. Would appreciate any ideas.
>
> > example
> > FOOHOME=/usr/local/foo/
> > I want to rsh to machine b from machine a and run a command as user
> > foo
>
> > from machine a
> > #rsh -n machineb "su - foo - c '$FOOHOME/bin/command'"
>
> Can't you just use "-l foo" in the rsh command line?

I need to use a .rsh for this and I would prefer not to for security.
Also, this still wont allow me to expand the variable $FOOHOME
littlehelphere [ Mi, 09 Januar 2008 23:19 ] [ ID #1903327 ]

Re: rsh to host and run command as another user

littlehelphere [at] gmail.com wrote:

>> > from machine a
>> > #rsh -n machineb "su - foo - c '$FOOHOME/bin/command'"
>>
>> Can't you just use "-l foo" in the rsh command line?
>
> I need to use a .rsh for this and I would prefer not to for security.
> Also, this still wont allow me to expand the variable $FOOHOME

Ah ok, so /that/ the problem was (it was not clear from your first post).
Well, you put the variable inside single quotes, so it's not expanded.
PK [ Mi, 09 Januar 2008 23:37 ] [ ID #1903328 ]

Re: rsh to host and run command as another user

In article <fm3hbu$m49$1 [at] aioe.org>, pk <pk [at] pk.pk> wrote:

> littlehelphere [at] gmail.com wrote:
>
> >> > from machine a
> >> > #rsh -n machineb "su - foo - c '$FOOHOME/bin/command'"
> >>
> >> Can't you just use "-l foo" in the rsh command line?
> >
> > I need to use a .rsh for this and I would prefer not to for security.

So you want to be asked for their password?

Although there's an rexecd server that implements this (executing a
command line using password authentication rather than .rhosts), I don't
think most Unix systems provide a command like rsh that connects to it.

Can you use ssh rather than rsh? That will allow you to do this, and it
doesn't send the password over the network.

> > Also, this still wont allow me to expand the variable $FOOHOME
>
> Ah ok, so /that/ the problem was (it was not clear from your first post).
> Well, you put the variable inside single quotes, so it's not expanded.

But the single quotes are inside double quotes, should it IS expanded.

--
Barry Margolin, barmar [at] alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
Barry Margolin [ Mi, 09 Januar 2008 23:46 ] [ ID #1903332 ]

Re: rsh to host and run command as another user

On Jan 9, 5:46 pm, Barry Margolin <bar... [at] alum.mit.edu> wrote:
> In article <fm3hbu$m4... [at] aioe.org>, pk <p... [at] pk.pk> wrote:
> > littlehelph... [at] gmail.com wrote:
>
> > >> > from machine a
> > >> > #rsh -n machineb "su - foo - c '$FOOHOME/bin/command'"
>
> > >> Can't you just use "-l foo" in the rsh command line?
>
> > > I need to use a .rsh for this and I would prefer not to for security.
>
> So you want to be asked for their password?
>
> Although there's an rexecd server that implements this (executing a
> command line using password authentication rather than .rhosts), I don't
> think most Unix systems provide a command like rsh that connects to it.
>
> Can you use ssh rather than rsh? That will allow you to do this, and it
> doesn't send the password over the network.
>
> > > Also, this still wont allow me to expand the variable $FOOHOME
>
> > Ah ok, so /that/ the problem was (it was not clear from your first post).
> > Well, you put the variable inside single quotes, so it's not expanded.
>
> But the single quotes are inside double quotes, should it IS expanded.
>
> --
> Barry Margolin, bar... [at] alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***
> *** PLEASE don't copy me on replies, I'll read them in the group ***

so for ssh I would need to put the pub key in place, right? Anything
else? Beyond the single quotes is the remainder of the command OK?
littlehelphere [ Do, 10 Januar 2008 00:57 ] [ ID #1904168 ]

Re: rsh to host and run command as another user

Barry Margolin wrote:

> But the single quotes are inside double quotes, should it IS expanded.

You are correct, my fault. Sorry for overlooking that.
PK [ Do, 10 Januar 2008 09:43 ] [ ID #1904177 ]

Re: rsh to host and run command as another user

littlehelphere [at] gmail.com wrote:

> so for ssh I would need to put the pub key in place, right? Anything
> else? Beyond the single quotes is the remainder of the command OK?

The single quotes are not a problem, as Barry correctly pointed out. With
ssh, and the appropriate keys in place, you could just do

ssh foo [at] machineb $FOOHOME/bin/command

and you should be OK.
PK [ Do, 10 Januar 2008 09:46 ] [ ID #1904178 ]
Linux » comp.unix.shell » rsh to host and run command as another user

Vorheriges Thema: Urgent req for Unix Shell Script Developer
Nächstes Thema: Know my the IP/interface being used by current tty/shell