Unix Shell - Run a script across servers

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > January 2006 > Run a script across servers





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 Run a script across servers
Sashi

2006-01-13, 10:40 pm

Hi, I have an application that runs on three Linux boxes. From my
development box, I've set up ssh to skip passwords when I login to
these three boxes hosting my application. To check the status of this
application, I'll have to login to each of these boxes, and run the
command to check the status and log out again.
Can someone give me an idea of how to set up a script that'll ssh into
these boxes, cd to the app dir and run the script to check the status
of the components?
As an example, I wrote a test script
hostname
ssh my_user@box1
hostname
When run on dev box, it prints the hostname of my dev box, logs me into
the app host but halts. I need to log out and the hostname of dev box
is again printed. How do I get the hostname of the app host to print?
Once I have that, I can manage the rest.
TIA,
Sashi

Jeremiah DeWitt Weiner

2006-01-13, 10:40 pm

Sashi <smalladi@gmail.com> wrote:
> As an example, I wrote a test script
> hostname
> ssh my_user@box1
> hostname


> When run on dev box, it prints the hostname of my dev box, logs me into
> the app host but halts.


You know that ssh can take a command, right? Try
ssh my_user@box1 "hostname"

That should get you moving in the right direction. The reason it
doesn't work the way you thought it would in your test script is because
each command is spawned off separately. When the first 'hostname'
finishes, then ssh will run. When ssh finishes, then the second
'hostname' will run. The second 'hostname' doesn't get fed to the ssh
command as input any more than the ssh command gets fed to the first
hostname command!

--
Oh to have a lodge in some vast wilderness. Where rumors of oppression
and deceit, of unsuccessful and successful wars may never reach me
anymore.
-- William Cowper
Sashi

2006-01-13, 10:40 pm


Jeremiah DeWitt Weiner wrote:
> Sashi <smalladi@gmail.com> wrote:
>
>
> You know that ssh can take a command, right? Try
> ssh my_user@box1 "hostname"
>
> That should get you moving in the right direction. The reason it
> doesn't work the way you thought it would in your test script is because
> each command is spawned off separately. When the first 'hostname'
> finishes, then ssh will run. When ssh finishes, then the second
> 'hostname' will run. The second 'hostname' doesn't get fed to the ssh
> command as input any more than the ssh command gets fed to the first
> hostname command!

Yes, that much was obvious.
But I can run builtins by giving a command to ssh but not user-defined
scripts.
For exampls ssh my_user@box1 "hostname" who
prints out all the users but
ssh my_user@box1 "hostname" /full/path/to/my/script/ doesn't work.
How do I do that?
Thanks,
Sashi
>
> --
> Oh to have a lodge in some vast wilderness. Where rumors of oppression
> and deceit, of unsuccessful and successful wars may never reach me
> anymore.
> -- William Cowper


Kevin Collins

2006-01-13, 10:40 pm

In article <1137001030.658226.154380@g43g2000cwa.googlegroups.com>, Sashi wrote:
>
> Jeremiah DeWitt Weiner wrote:
> Yes, that much was obvious.
> But I can run builtins by giving a command to ssh but not user-defined
> scripts.
> For exampls ssh my_user@box1 "hostname" who
> prints out all the users but
> ssh my_user@box1 "hostname" /full/path/to/my/script/ doesn't work.
> How do I do that?


Specify the full path to the command:

ssh my_user@box1 /some/path/script

or, if you need to be in a certain directory:

ssh my_user@box1 'cd /some/path; ./script'

Kevin

--
Unix Guy Consulting, LLC
Unix and Linux Automation, Shell, PERL and CGI scripting
http://www.unix-guy.com
Sashi

2006-01-13, 10:40 pm

> Specify the full path to the command:
>
> ssh my_user@box1 /some/path/script
>
> or, if you need to be in a certain directory:
>
> ssh my_user@box1 'cd /some/path; ./script'
>
> Kevin
>
> --
> Unix Guy Consulting, LLC
> Unix and Linux Automation, Shell, PERL and CGI scripting
> http://www.unix-guy.com


Thanks, Kevin, it worked.
Sashi

Sashi

2006-01-13, 10:40 pm

> Specify the full path to the command:
>
> ssh my_user@box1 /some/path/script
>
> or, if you need to be in a certain directory:
>
> ssh my_user@box1 'cd /some/path; ./script'
>
> Kevin
>
> --
> Unix Guy Consulting, LLC
> Unix and Linux Automation, Shell, PERL and CGI scripting
> http://www.unix-guy.com


Thanks, Kevin and Jeremiah, it worked.
Sashi

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com