Re: Shuting down servers
by roboticus (Chancellor) on Mar 15, 2011 at 10:12 UTC
|
subhash_fire:
With no information about what OS you're trying to shut down, no mention of the command to do so, and no attempt to solve it on your own? This isn't a code-writing service, you should put in some effort, if only to ask a question.
...roboticus
When your only tool is a hammer, all problems look like your thumb.
| [reply] |
|
|
Thanks Mr. Roboticus i am sorry for the minimal information provided.
I am using a window machine from that machine i need to login a linux based interface OA through ssh where i need to shutdown all servers at once. Instead of doing one by one which is time consuming.<\P>
I tried using
<code>
@server = (1 .. 5);
foreach (@servers)
{
exec ("poweroff server $_");
}
<\code>
Since I doesn't want the status of the command output for poweroff so used exec command. Is this info enough for you? Thanks in advance.
<\p>
| [reply] |
|
|
subhash_fire:
Better. So you have a "poweroff server" command that takes a number and shuts down the appropriate server? So I'm guessing that the poweroff command is not returning until the server actually shuts down.
If that's the case, then perhaps the easiest way would be to use a batch file like:
@echo off
start poweroff server 1
start poweroff server 2
start poweroff server 3
start poweroff server 4
start poweroff server 5
That way, the command shell can fire off the five poweroff commands in their own separate processes.
...roboticus
When your only tool is a hammer, all problems look like your thumb. | [reply] [d/l] |
Re: Shuting down servers
by deorth (Scribe) on Mar 15, 2011 at 10:44 UTC
|
Well, even with such minimal information there are directions we can pursue.
You need a transit mechanism to the remote hosts. Net::SSH::Perl is my favourite but YMMV. The 'shutdown_command' is merely a static variable so we can ignore that.
We need some form of single sign-on to the machines, I would recommend ssh-agent with keys loaded for a user that has sudo on the remote machines.
Then you'll need to code to grab sudo and run your commands.
Wrapped around all of this you'll need a flexible multi-machine connection engine that will handle inputs and returns and report back anomalies in a sane manner.
Is that enough to get you started ? :)
| [reply] |
|
|
Thanks Mr. Deorth.
Let me try it and update you.
| [reply] |
Re: Shuting down servers
by jethro (Monsignor) on Mar 15, 2011 at 12:03 UTC
|
To handle things concurrently you have the following options:
1) Use multiple processes, i.e. with fork() or something like Fork::Manager
2) Use threads
3) Start the shutdown commands without waiting for their completion, i.e. use the shells ability to run processes in the background by adding '&' to the end of a command
Option 2 is probably the most suitable option for Windows, on Linux pick any one
| [reply] |
Re: Shuting down servers
by salva (Canon) on Mar 15, 2011 at 12:20 UTC
|
use Net::OpenSSH::Parallel;
my $pssh = Net::OpenSSH::Parallel->new();
$pssh->add_host($_) for @servers;
$pssh->push('*', command => 'poweroff');
$pssh->run;
Though, note that Net::OpenSSH::Parallel does not work on Windows. | [reply] [d/l] |
Re: Shuting down servers
by subhash_fire (Novice) on Mar 15, 2011 at 11:58 UTC
|
Thanks Mr. Roboticus i am sorry for the minimal information provided. I am using a window machine from that machine i need to login a linux based interface OA through ssh where i need to shutdown all servers at once. Instead of doing one by one which is time consuming.<\P> I tried using <code> @server = (1 .. 5); foreach (@servers) { exec ("poweroff server $_"); } <\code>
Since I doesn't want the status of the command output for poweroff so used exec command. Is this info enough for you? Thanks in advance. <\p>
| [reply] |
|
|
exec is not the right function as it replaces your script with the command, i.e. the call to exec will always be the last thing your script will do.
Use system() instead. And try either "poweroff server $_ &" or "nohup poweroff server $_ &", this might already be all you need to do to make it work
PS: Use </code> instead of <\code>
| [reply] |