|
Home > Archive > Unix Programming > February 2007 > Execute command on remote machine
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Execute command on remote machine
|
|
| Christopher Benson-Manica 2007-02-14, 7:21 pm |
| I am looking for a way to asynchronously execute a command on a remote
machine, that is, to start a process on a remote machine that
continues running after the login shell/session/whatever expires. Is
there a command that can do this? If not, it occurs to me that it
would theoretically be possible to remotely schedule a cron job for
immediate execution on the remote machine, although that is abhorrent
on enough levels that I'm sure it's not an option.
--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
| |
| CptDondo 2007-02-14, 7:21 pm |
| Christopher Benson-Manica wrote:
> I am looking for a way to asynchronously execute a command on a remote
> machine, that is, to start a process on a remote machine that
> continues running after the login shell/session/whatever expires. Is
> there a command that can do this? If not, it occurs to me that it
> would theoretically be possible to remotely schedule a cron job for
> immediate execution on the remote machine, although that is abhorrent
> on enough levels that I'm sure it's not an option.
>
I've done this via inetd. Create a script that authenticates, or does
whatever magic it needs to be sure of the validity of the request, and
then launches your app.
Hook it to a port on the target machine. Connect via
telnet/php/perl/whatever, send your credentials, and whammo, the proggie
is running. I've done this for stuff that doesn't need ssh-type security.
Pretty easy once you figure it out.
--Yan
| |
| Eric Sosman 2007-02-14, 7:21 pm |
| Christopher Benson-Manica wrote On 02/14/07 16:32,:
> I am looking for a way to asynchronously execute a command on a remote
> machine, that is, to start a process on a remote machine that
> continues running after the login shell/session/whatever expires. Is
> there a command that can do this? If not, it occurs to me that it
> would theoretically be possible to remotely schedule a cron job for
> immediate execution on the remote machine, although that is abhorrent
> on enough levels that I'm sure it's not an option.
"man rsh" might be a good place to start.
--
Eric.Sosman@sun.com
| |
| William Ahern 2007-02-14, 7:21 pm |
| On Wed, 14 Feb 2007 21:32:13 +0000, Christopher Benson-Manica wrote:
> I am looking for a way to asynchronously execute a command on a remote
> machine, that is, to start a process on a remote machine that
> continues running after the login shell/session/whatever expires. Is
> there a command that can do this? If not, it occurs to me that it
> would theoretically be possible to remotely schedule a cron job for
> immediate execution on the remote machine, although that is abhorrent
> on enough levels that I'm sure it's not an option.
>
What's wrong with
ssh nobody@some.machine 'nohup some_command </dev/null >/dev/null 2>&1 &'
Of course, you'd probably want to setup shared keys for authentication.
| |
| Christopher Benson-Manica 2007-02-14, 7:21 pm |
| Eric Sosman <Eric.Sosman@sun.com> wrote:
> "man rsh" might be a good place to start.
Perhaps the man pages on my system are deficient, but I don't see
anything in rsh or rlogin which suggests that either will start a
process on the remote machine that won't terminate when the connection
to the remote machine is broken. "rsh normally terminates when the
remote command does" - which is not what I want - and the cases that
statement does not cover are, by my reading, the cases where no
command to rsh is specified and you get a login shell courtesy of
rlogin. Am I missing something?
--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
| |
| Kenny McCormack 2007-02-14, 7:21 pm |
| In article <1171489657.329318@news1nwk>,
Eric Sosman <Eric.Sosman@sun.com> wrote:
>Christopher Benson-Manica wrote On 02/14/07 16:32,:
>
> "man rsh" might be a good place to start.
Or rexec (which has been around since forever).
Something about this post (including the poster's identity) tells me
that there is something more complex/unstated about the request. I.e.,
the question as stated is too "normal newbie" to be taken at face value.
| |
| Roberto Waltman 2007-02-14, 7:21 pm |
| Christopher Benson-Manica wrote:
>Perhaps the man pages on my system are deficient, but I don't see
>anything in rsh or rlogin which suggests that either will start a
>process on the remote machine that won't terminate when the connection
>to the remote machine is broken. "rsh normally terminates when the
>remote command does" - which is not what I want - and the cases that
>statement does not cover are, by my reading, the cases where no
>command to rsh is specified and you get a login shell courtesy of
>rlogin. Am I missing something?
see 'man nohup' - Then (bash example)
nohup [command] [parameters] >/dev/null 2>&1 &
Roberto Waltman
[ Please reply to the group,
return address is invalid ]
| |
| Pascal Bourguignon 2007-02-14, 7:21 pm |
| William Ahern <william@25thandClement.com> writes:
> On Wed, 14 Feb 2007 21:32:13 +0000, Christopher Benson-Manica wrote:
>
>
> What's wrong with
>
> ssh nobody@some.machine 'nohup some_command </dev/null >/dev/null 2>&1 &'
>
> Of course, you'd probably want to setup shared keys for authentication.
And you can also have a look at at(1) and batch(1), if not at
crontab(1) on the remote...
--
__Pascal Bourguignon__ http://www.informatimago.com/
ADVISORY: There is an extremely small but nonzero chance that,
through a process known as "tunneling," this product may
spontaneously disappear from its present location and reappear at
any random place in the universe, including your neighbor's
domicile. The manufacturer will not be responsible for any damages
or inconveniences that may result.
| |
| Eric Sosman 2007-02-15, 1:27 am |
| Christopher Benson-Manica wrote:
> Eric Sosman <Eric.Sosman@sun.com> wrote:
>
>
> Perhaps the man pages on my system are deficient, but I don't see
> anything in rsh or rlogin which suggests that either will start a
> process on the remote machine that won't terminate when the connection
> to the remote machine is broken. "rsh normally terminates when the
> remote command does" - which is not what I want - and the cases that
> statement does not cover are, by my reading, the cases where no
> command to rsh is specified and you get a login shell courtesy of
> rlogin. Am I missing something?
rsh remotehost [-l remoteuser] command args \&
In other words, the remote command consists of starting
"command args" as a background task. "command args &" completes
immediately, so rsh completes immediately, but "command args"
runs on the remote machine until it feels like stopping.
Extra credit: Redirect stdin/out/err of "command args".
--
Eric Sosman
esosman@acm-dot-org.invalid
| |
| Peter van Hooft 2007-02-15, 1:27 am |
| On 2007-02-15, Pascal Bourguignon <pjb@informatimago.com> wrote:
> William Ahern <william@25thandClement.com> writes:
>
>
> And you can also have a look at at(1) and batch(1), if not at
> crontab(1) on the remote...
>
>
The idea of doing this with cron is feasible, but bound to
bite you in the behind when you forget to remove the crontab entry
afterwards.
One way of doing this is running it with at(1).
echo command | ssh host at now
peter
| |
| Christopher Benson-Manica 2007-02-15, 1:19 pm |
| William Ahern <william@25thandclement.com> wrote:
> What's wrong with
> ssh nobody@some.machine 'nohup some_command </dev/null >/dev/null 2>&1 &'
Nothing - I wasn't aware of nohup and I think it will do the trick,
once I figure out why this works with simple commands and not the
shell script I'd like to invoke. Thanks.
--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
|
|
|
|
|