LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Script that turns off a list of servers in network (https://www.linuxquestions.org/questions/programming-9/script-that-turns-off-a-list-of-servers-in-network-725352/)

Ajit Gunge 05-12-2009 01:34 AM

Script that turns off a list of servers in network
 
Hi all,
Can anyone help me write a script(cron Job) that will automatically turn off a list of servers that are connected over a lan.Is there any way I can do this or anywhere I can find this one.

Thanks,
Ajit

repo 05-12-2009 01:38 AM

you can use nmap
Code:

nmap -sP -PI -PT 10.0.0.0/24

ghostdog74 05-12-2009 02:08 AM

what do you mean by "turn off". do you want to do a remote shutdown ?

Ajit Gunge 05-12-2009 02:33 AM

Quote:

Originally Posted by ghostdog74 (Post 3537908)
what do you mean by "turn off". do you want to do a remote shutdown ?

Yes you are correct I want to do is a remote shutdown.

Ajit

Ajit Gunge 05-12-2009 02:50 AM

Quote:

Originally Posted by repo (Post 3537885)
you can use nmap
Code:

nmap -sP -PI -PT 10.0.0.0/24

IS there an exe for nmap available for a windows machine that I can readily use.

Ajit

ghostdog74 05-12-2009 03:21 AM

you don't do remote shutdown using nmap.

Ajit Gunge 05-12-2009 04:38 AM

Quote:

Originally Posted by ghostdog74 (Post 3537967)
you don't do remote shutdown using nmap.

So is there any way that I can run the shutdown command remotely.

Ajit

Sergei Steshenko 05-12-2009 05:38 AM

Quote:

Originally Posted by Ajit Gunge (Post 3538024)
So is there any way that I can run the shutdown command remotely.

Ajit

I think you are missing the point.

You have been suggested how to discover servers on your local network using 'nmap'.

Then knowing the IP addresses, you can shut down the servers using the commands that are supposed to perform the shutdown and supplying the commands with IP addresses discovered by 'nmap'.

Probably shutdown can be done through 'ssh' login to the server to be shut down, and then calling 'poweroff', but most likely you have to eventually become root on the server.

Ajit Gunge 05-12-2009 07:26 AM

I got U.
With nmap I can find the ip of the different servers.
Thanks for that additional information.Here in my case I know the ip addresses of the servers but how do I proceed from here.
I will tell you my requirement in short I have to run a script actually that too should run automatically at some predefined time which does the following

logins into the servers.
Later can su as root and than run the shutdown command which will shutdown all the servers within that script.

Thanks
Ajit

jim80net 05-12-2009 07:41 AM

install a ssh key for an admin account on each of the servers you want shutdown, then call shutdown -whatever whenever from your script.

Ajit Gunge 05-12-2009 08:59 AM

ok.Still I am not able to to whatever is required.Can someone help me out with the script.

Ajit

Sergei Steshenko 05-12-2009 09:06 AM

Quote:

Originally Posted by Ajit Gunge (Post 3538248)
ok.Still I am not able to to whatever is required.Can someone help me out with the script.

Ajit

You do not describe what you exactly did and what the problems were - error messages, etc.

Or you want us to write a script for you ?

jim80net 05-12-2009 03:46 PM

http://www.freeos.com/guides/lsst/ <-- Great BASH tutorial.

Ajit Gunge 05-13-2009 01:12 AM

I dont want you to write a script for me but if you people can help me out that will be great.

The script that I have written is as below
spawn telnet 135.27.153.243
shutdown -t 180 135.27.153.201

And the error that I get when I run the script is

invalid command name "shutdown"
while executing
"shutdown -t 180 135.27.153.201"
(file "./shut_down" line 3)

Ajit

Sergei Steshenko 05-13-2009 06:54 AM

Quote:

Originally Posted by Ajit Gunge (Post 3539016)
I dont want you to write a script for me but if you people can help me out that will be great.

The script that I have written is as below
spawn telnet 135.27.153.243
shutdown -t 180 135.27.153.201

And the error that I get when I run the script is

invalid command name "shutdown"
while executing
"shutdown -t 180 135.27.153.201"
(file "./shut_down" line 3)

Ajit

I am sorry, but it appears you lack basic understanding of how things work.
  1. what is 'spawn' and why are you calling it ?
  2. why 'telnet' and 'shutdown' have different IP addresses as their arguments ?
  3. why 'shutdown' has IP address as its argument ?

Based on which manual pages did you choose your commands and arguments ? Specifically, can you show me the lines in 'man shutdown' which mention IP address ?

Did you perform successful remote shutdown manually ? If yes, what did you exactly do ? If not, why do you start with a script in the first place ?

The last, but not least: do you first read man pages or do you first bother other people ?


All times are GMT -5. The time now is 10:45 AM.