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/)

abs_77 05-14-2009 05:16 AM

One more workaround you can do using SSH

You would generate single key pair without passphrase using command ssh-keygen from where you would execute your script.
Place Public key to all of the servers. Keep private key onto the system from where you would execute script using cronjob

How the script is going to be?
You would write the script from where you would execute the command.
Bring all the servers(ips)in loop or array.
Login on to server one by one using ssh command by using private key
and execute shutdown command then exit

For more detail check ssh manual at (http://www.openssh.org)
another bash tutorial(http://www.linuxconfig.org/Bash_scripting_Tutorial)

Ofcourse, You would be shown the way to reach destination
but no one would lead you there.

ABS

schneidz 05-14-2009 09:21 AM

um, would:
Code:

ssh user@server sudo /sbin/shutdown -h now
not work ?

Ajit Gunge 05-14-2009 09:31 AM

Thanks All for all the important pointers.Its true,all one needs is pointer and I am on my way.I will definitely share this script ones its done.Maybe we can further enrich this one once we are through.

Thanks
Ajit

Sergei Steshenko 05-14-2009 09:47 AM

Quote:

Originally Posted by schneidz (Post 3540583)
um, would:
Code:

ssh user@server sudo /sbin/shutdown -h now
not work ?

The OP hasn't stated he tried it this way.

Ajit Gunge 05-14-2009 10:30 AM

Quote:

Originally Posted by Sergei Steshenko (Post 3540614)
The OP hasn't stated he tried it this way.

I tried this one but what it does is asks me for an input once it logins to the switch the output is

The authenticity of host '135.27.153.243 (135.27.153.243)' can't be established.
RSA key fingerprint is c1:99:8c:2e:37:42:e5:0f:02:84:47:85:e2:1c:cd:29.
Are you sure you want to continue connecting (yes/no)?

And now I have to enter is yes

But I dont want to input anything I want my script to do this.

Ajit

chrism01 05-14-2009 11:10 PM

But it only asks that once for a new machine, then it memorizes it for future ref. Its a security feature, see man-in-the-middle attack.

Ajit Gunge 05-15-2009 01:28 AM

Script still failing.....
 
Quote:

Originally Posted by chrism01 (Post 3541347)
But it only asks that once for a new machine, then it memorizes it for future ref. Its a security feature, see man-in-the-middle attack.

yeah you are right.It asks only once.Now my problem is I have to change the user to root to run the shutdown command on the list of servers.I think I will have to use expect for this purpose.
The error I receive is
Sorry, user init is not allowed to execute '/sbin/shutdown -h now' as root on S.

Thanks,
Ajit

chrism01 05-15-2009 01:36 AM

Add init to sudoers file and give him ability to run that cmd.

Ajit Gunge 05-15-2009 02:22 AM

Quote:

Originally Posted by chrism01 (Post 3541456)
Add init to sudoers file and give him ability to run that cmd.

Hmmmm...I will try to explain what I did and than you can tell me what I did wrong.

I added this entry in the sudoers file
vi /etc/sudoers.

init ALL=/sbin/shutdown.

And I run my script but it still gives me the same error.
Obviously I did something wrong but what is it?

Ajit

schneidz 05-15-2009 09:06 AM

this works in fedora:
http://www.linuxquestions.org/questi...1/#post3441308

is init some sort of special system user that has to do with the init command ?

Sergei Steshenko 05-15-2009 09:38 AM

Quote:

Originally Posted by Ajit Gunge (Post 3541483)
Hmmmm...I will try to explain what I did and than you can tell me what I did wrong.

I added this entry in the sudoers file
vi /etc/sudoers.

init ALL=/sbin/shutdown.

And I run my script but it still gives me the same error.
Obviously I did something wrong but what is it?

Ajit

Do you want anybody on the network to be able to shut down any server whenever he/she wants ?

Sergei Steshenko 05-15-2009 09:40 AM

Quote:

Originally Posted by Ajit Gunge (Post 3541483)
Hmmmm...I will try to explain what I did and than you can tell me what I did wrong.

I added this entry in the sudoers file
vi /etc/sudoers.

init ALL=/sbin/shutdown.

And I run my script but it still gives me the same error.
Obviously I did something wrong but what is it?

Ajit

Please stop waisting our time.
  1. publish thew script source (copy-paste);
  2. publish the exact command line (copy-paste);
  3. publish the script screen output (copy-paste).

schneidz 05-15-2009 09:47 AM

Quote:

Originally Posted by Sergei Steshenko (Post 3541861)
Do you want anybody on the network to be able to shout down any server whenever he/she wants ?

i tried shouting down my server but it just sits there blinking at me moronically.

Sergei Steshenko 05-15-2009 10:01 AM

Quote:

Originally Posted by schneidz (Post 3541879)
i tried shouting down my server but it just sits there blinking at me moronically.

Fixed.

schneidz 05-15-2009 10:36 AM

^ but now my previous post isnt funny anymore...


All times are GMT -5. The time now is 06:22 AM.