remsh a function in the current script
remsh a function in the current script
am 05.09.2007 18:30:41 von rachit7
I have a script something like this:
#!/bin/ksh
function remote_host {
remsh
}
function local_host {
#some commands
}
#more commands
local_host
remote_host
# Script ends
I want to remsh the local_host function to a remote host (through
remote_host function) and get back the output to the local host. I
know remsh runs only those commands that are present in the remote
hosts. Is there any worlaround for this problem. One option would be
to rcp the function in the /tmp dir and run it from there. But what if
I don't what to copy it to /tmp dir. Any other method?
Regards,
RB
Re: remsh a function in the current script
am 06.09.2007 21:18:48 von spcecdt
In article <1189009841.675412.98690@57g2000hsv.googlegroups.com>,
itsme wrote:
>I have a script something like this:
>
>
>#!/bin/ksh
>
>function remote_host {
>remsh
>}
>
>function local_host {
>#some commands
>}
>#more commands
>local_host
>remote_host
># Script ends
>
>I want to remsh the local_host function to a remote host (through
>remote_host function) and get back the output to the local host. I
>know remsh runs only those commands that are present in the remote
>hosts. Is there any worlaround for this problem. One option would be
>to rcp the function in the /tmp dir and run it from there. But what if
>I don't what to copy it to /tmp dir. Any other method?
Assuming your shell on the remote host is ksh, and if your local_host
function is one that would work properly if rcp'd over and executed,
you can simply make the function be part of the command passed:
rsh remote-host '
function local_host {
#some commands
}
local_host
'
If your shell on the remote host isn't ksh, you'd do approximately the same
thing, but invoke ksh explicitly on the remote host with the
function/invocation as its arguments. You'll have to make the quoting work.
Alternately, you can send the function over as the input to the shell:
rsh remote-host ksh <<\END
function local_host {
#some commands
}
local_host
END
John
--
John DuBois spcecdt@armory.com KC6QKZ/AE http://www.armory.com/~spcecdt/
Re: remsh a function in the current script
am 07.09.2007 14:37:01 von rachit7
On Sep 6, 3:18 pm, spce...@armory.com (John DuBois) wrote:
> In article <1189009841.675412.98...@57g2000hsv.googlegroups.com>,
>
>
>
> itsme wrote:
> >I have a script something like this:
>
> >#!/bin/ksh
>
> >function remote_host {
> >remsh
> >}
>
> >function local_host {
> >#some commands
> >}
> >#more commands
> >local_host
> >remote_host
> ># Script ends
>
> >I want to remsh the local_host function to a remote host (through
> >remote_host function) and get back the output to the local host. I
> >know remsh runs only those commands that are present in the remote
> >hosts. Is there any worlaround for this problem. One option would be
> >to rcp the function in the /tmp dir and run it from there. But what if
> >I don't what to copy it to /tmp dir. Any other method?
>
> Assuming your shell on the remote host is ksh, and if your local_host
> function is one that would work properly if rcp'd over and executed,
> you can simply make the function be part of the command passed:
>
> rsh remote-host '
> function local_host {
> #some commands
>
> }
>
> local_host
> '
>
> If your shell on the remote host isn't ksh, you'd do approximately the same
> thing, but invoke ksh explicitly on the remote host with the
> function/invocation as its arguments. You'll have to make the quoting work.
>
> Alternately, you can send the function over as the input to the shell:
>
> rsh remote-host ksh <<\END
> function local_host {
> #some commands
>
> }
>
> local_host
> END
>
> John
> --
> John DuBois spce...@armory.com KC6QKZ/AE http://www.armory.com/~spcecdt/
Thanks a lot John. I will try it. But it seems that in this case I
will not be able to invoke this function in the local machine.
I want to be able to use it on both local and remote machines.
Thanks anyway.
Regards
RB
Re: remsh a function in the current script
am 07.09.2007 17:14:14 von rachit7
On Sep 7, 8:37 am, itsme wrote:
> On Sep 6, 3:18 pm, spce...@armory.com (John DuBois) wrote:
>
>
>
>
>
> > In article <1189009841.675412.98...@57g2000hsv.googlegroups.com>,
>
> > itsme wrote:
> > >I have a script something like this:
>
> > >#!/bin/ksh
>
> > >function remote_host {
> > >remsh
> > >}
>
> > >function local_host {
> > >#some commands
> > >}
> > >#more commands
> > >local_host
> > >remote_host
> > ># Script ends
>
> > >I want to remsh the local_host function to a remote host (through
> > >remote_host function) and get back the output to the local host. I
> > >know remsh runs only those commands that are present in the remote
> > >hosts. Is there any worlaround for this problem. One option would be
> > >to rcp the function in the /tmp dir and run it from there. But what if
> > >I don't what to copy it to /tmp dir. Any other method?
>
> > Assuming your shell on the remote host is ksh, and if your local_host
> > function is one that would work properly if rcp'd over and executed,
> > you can simply make the function be part of the command passed:
>
> > rsh remote-host '
> > function local_host {
> > #some commands
>
> > }
>
> > local_host
> > '
>
> > If your shell on the remote host isn't ksh, you'd do approximately the same
> > thing, but invoke ksh explicitly on the remote host with the
> > function/invocation as its arguments. You'll have to make the quoting work.
>
> > Alternately, you can send the function over as the input to the shell:
>
> > rsh remote-host ksh <<\END
> > function local_host {
> > #some commands
>
> > }
>
> > local_host
> > END
>
> > John
> > --
> > John DuBois spce...@armory.com KC6QKZ/AE http://www.armory.com/~spcecdt/
>
> Thanks a lot John. I will try it. But it seems that in this case I
> will not be able to invoke this function in the local machine.
> I want to be able to use it on both local and remote machines.
>
> Thanks anyway.
> Regards
> RB- Hide quoted text -
>
> - Show quoted text -
Folks,
I came up with a solution
#!/bin/ksh
LOCALHOST='
hostname;pwd;uname;$HOME
'
function remote_host {
echo $LOCALHOST | xargs remsh REMOTE_HOST_NAME
}
remote_host # To run on remote host
echo
eval $(echo $LOCALHOST) # To run on local host.
# End of script
Regards,
RB