[SOLVED] Script that turns off a list of servers in network
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am sorry if I am wasting your time.I am a newbie and still picking up things.The details are
Script source
#!/bin/bash
ssh init@135.27.162.214 sudo /sbin/shutdown -h now
The script has been given the execute permissions
-rwxr-xr-x 1 root root 64 May 16 15:52 test.sh
and the command line I use is ./test.sh
The script screen output is as below
Sorry, user init is not allowed to execute '/sbin/shutdown -h now' as root on S8720_2_1.
Ajit
'man ssh' says you need to give a command, which is supposed to be the last argument - pay attention to the singular, not plural form of the "argument".
- pay attention to the single (in this case could also be double) quotes I've added.
Also pay attention to '-n' and look up in the manual what it means. Make sure you do need it, and have taken measures to be able to use it - otherwise you won't be able to run the script unattended.
Bow, don't just grab what I've given you, but try to understand why it didn't work - do you understand how shells deal with command line arguments ? I.e. do you understand how command line items are split ?
'man ssh' says you need to give a command, which is supposed to be the last argument - pay attention to the singular, not plural form of the "argument".
- pay attention to the single (in this case could also be double) quotes I've added.
Also pay attention to '-n' and look up in the manual what it means. Make sure you do need it, and have taken measures to be able to use it - otherwise you won't be able to run the script unattended.
Bow, don't just grab what I've given you, but try to understand why it didn't work - do you understand how shells deal with command line arguments ? I.e. do you understand how command line items are split ?
Ok...Now my script doesnt give any error as earlier but it doesnt do whats required,that is shutting down the server.
Ok...Now my script doesnt give any error as earlier but it doesnt do whats required,that is shutting down the server.
Ajit
So, what is happening in the server to be shut down ? I.e. are there any messages from it ? Are there any messages in /var/log/messages in the server to be shut down ?
And did you verify you need of '-n' ? Justify your answer.
It does login into the server,but asks for the password.
It doesnt return any error but also doesnt turn off the server.
Ajit
Again, you are waisting our time.
I wrote you earlier:
Quote:
Also pay attention to '-n' and look up in the manual what it means. Make sure you do need it, and have taken measures to be able to use it - otherwise you won't be able to run the script unattended.
, and you haven't performed the requested action.
To start performing the requested action you need to do
Code:
man ssh
and find the paragraph related to '-n' switch. In my case the paragraph is just 4 (four) lines long.
Read the paragraph and make sure you understand what it says/means, if something is not clear, ask further questions here.
2- aside from pulling the plug, how does one shutdown that computer ?
maybe a look inside /var/log/messages will clue us into what is going on ?
im surprised no error message (like 'user 'init' not in sudoers file). maybe if you do visudo as root and make sure init is in there. copy and paste those lines in here so we can see.
2- aside from pulling the plug, how does one shutdown that computer ?
maybe a look inside /var/log/messages will clue us into what is going on ?
im surprised no error message (like 'user 'init' not in sudoers file). maybe if you do visudo as root and make sure init is in there. copy and paste those lines in here so we can see.
I am sorry but after following the steps to configure the passwordless_logins
Here are the steps I did for the same.I have two servers namely S8300B_6(135.27.153.201) and the other is S8300_8(135.27.153.206)
On S8300B_6 I am doing the following steps as root
root@S8300B_6> ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa):{I enter}
/root/.ssh/id_dsa already exists.
Overwrite (y/n)?{y}
Enter passphrase (empty for no passphrase):{I enter}
Enter same passphrase again:{I enter}
The key fingerprint is:
28:07:aa:29:2a:e3:19:21:a8:cc:a0:f2:7d:2a:78:66 root@S8300B_6
Now I run
scp .ssh/id_dsa.pub init@135.27.153.206:~/.ssh/authorized_keys
Than I run the command
ssh 135.27.153.206 but again it asks me password.
2- aside from pulling the plug, how does one shutdown that computer ?
Using the shutdown command I can shut the machine.Correct me if I am wrong.
I checked the /var/log/messages file but there were no new entries there.
The lines added by me in sudoers files is as below and also the set of commands that I used
visudo -f /etc/sudoers
This opens a /etc/sudoers.tmp file
and at the last of the file I have added these lines
init ALL=/sbin/shutdown
1- i wouldnt do it as root, the link was just an example.
it seems like root's passwordless login is ok but init's is not. (i'll spell it out for ya'; run ssh-keygen -t dsa as init).
2- previousely you said the shutdown command didnt work for init even after you logged into a terminal session on that machine.
Quote:
Originally Posted by schneidz
once in 135.27.162.214 are you able to do sudo /sbin/shutdown -h now to shut it down while being logged in as init ?
Quote:
Originally Posted by Ajit Gunge
...
It doesnt return any error but also doesnt turn off the server.
Ajit
3- i dont know about the syntax of visudo (i usually just run visudo while being logged in as root) but look thru the comments of that file and see if there is some group or someplace you can add a user that will allow them to run "sudo shutdown" without prompting for the root passwd.
^ but shouldnt it have thrown a 'user not authorized' error ?
something here is fishy... and i dont like fish. except one time i was in a restaurant in martha's vineyard and had some crab cakes that was ok. i mean if i liked fish i wouldve loved it, but i didnt hate it...
something here is fishy... and i dont like fish. except one time i was in a restaurant in martha's vineyard and had some crab cakes that was ok. i mean if i liked fish i wouldve loved it, but i didnt hate it...
You're truly genius man! where's this sentence is taken from?!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.