PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > remsh a function in the current script
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

remsh a function in the current script

Réponse
 
LinkBack Outils de la discussion
Vieux 05/09/2007, 17h30   #1
itsme
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut remsh a function in the current script

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

  Réponse avec citation
Vieux 06/09/2007, 20h18   #2
John DuBois
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: remsh a function in the current script

In article <1189009841.675412.98690@57g2000hsv.googlegroups.c om>,
itsme <rachit7@gmail.com> 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/
  Réponse avec citation
Vieux 07/09/2007, 13h37   #3
itsme
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: remsh a function in the current script

On Sep 6, 3:18 pm, spce...@armory.com (John DuBois) wrote:
> In article <1189009841.675412.98...@57g2000hsv.googlegroups.c om>,
>
>
>
> itsme <rach...@gmail.com> 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

  Réponse avec citation
Vieux 07/09/2007, 16h14   #4
itsme
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: remsh a function in the current script

On Sep 7, 8:37 am, itsme <rach...@gmail.com> wrote:
> On Sep 6, 3:18 pm, spce...@armory.com (John DuBois) wrote:
>
>
>
>
>
> > In article <1189009841.675412.98...@57g2000hsv.googlegroups.c om>,

>
> > itsme <rach...@gmail.com> 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='
hostnamewd;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

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 07h15.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,16202 seconds with 12 queries