LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-16-2009, 05:25 AM   #31
Ajit Gunge
Member
 
Registered: Jan 2008
Location: Pune
Distribution: RHEL,fedora
Posts: 253

Original Poster
Blog Entries: 1

Rep: Reputation: 21

Quote:
Originally Posted by Sergei Steshenko View Post
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).
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
 
Old 05-16-2009, 06:35 AM   #32
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by Ajit Gunge View Post
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".

So, first try to change your command line to:

Code:
ssh -n init@135.27.162.214 'sudo /sbin/shutdown -h now'
- 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 ?
 
Old 05-16-2009, 07:18 AM   #33
Ajit Gunge
Member
 
Registered: Jan 2008
Location: Pune
Distribution: RHEL,fedora
Posts: 253

Original Poster
Blog Entries: 1

Rep: Reputation: 21
Quote:
Originally Posted by Sergei Steshenko View Post
'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".

So, first try to change your command line to:

Code:
ssh -n init@135.27.162.214 'sudo /sbin/shutdown -h now'
- 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.

Ajit
 
Old 05-16-2009, 07:53 AM   #34
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by Ajit Gunge View Post
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.
 
Old 05-17-2009, 02:22 PM   #35
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
are you able to do:
ssh init@135.27.162.214
without it asking you for a password ?

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 ?
____________________

works for me (fc-9 to rh-9):
Code:
[fedora@localhost System]$ ssh schneidz@hyper sudo /sbin/shutdown -h now
[fedora@localhost System]$

Last edited by schneidz; 05-18-2009 at 12:23 AM.
 
Old 05-18-2009, 02:35 AM   #36
Ajit Gunge
Member
 
Registered: Jan 2008
Location: Pune
Distribution: RHEL,fedora
Posts: 253

Original Poster
Blog Entries: 1

Rep: Reputation: 21
Quote:
Originally Posted by schneidz View Post
are you able to do:
ssh init@135.27.162.214
without it asking you for a password ?

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 ?
____________________:

works for me (fc-9 to rh-9):
Code:
[fedora@localhost System]$ ssh schneidz@hyper sudo /sbin/shutdown -h now
[fedora@localhost System]$
It does login into the server,but asks for the password.
It doesnt return any error but also doesnt turn off the server.

Ajit
 
Old 05-18-2009, 08:26 AM   #37
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by Ajit Gunge View Post
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.
 
Old 05-18-2009, 08:57 AM   #38
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by Ajit Gunge View Post
1- It does login into the server,but asks for the password.
2- It doesnt return any error but also doesnt turn off the server.

Ajit
1- seems like your passwordless login isnt setup correctly:
http://wiki.linuxquestions.org/wiki/PassWordLess_LogIns

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.

Last edited by schneidz; 05-18-2009 at 08:58 AM.
 
Old 05-18-2009, 10:19 AM   #39
Ajit Gunge
Member
 
Registered: Jan 2008
Location: Pune
Distribution: RHEL,fedora
Posts: 253

Original Poster
Blog Entries: 1

Rep: Reputation: 21
Quote:
Originally Posted by schneidz View Post
1- seems like your passwordless login isnt setup correctly:
http://wiki.linuxquestions.org/wiki/PassWordLess_LogIns

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


Ajit
 
Old 05-18-2009, 11:40 AM   #40
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
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 View Post
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 View Post
...
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.

Last edited by schneidz; 05-18-2009 at 11:44 AM.
 
Old 05-18-2009, 12:14 PM   #41
itz2000
Member
 
Registered: Jul 2005
Distribution: Fedora fc4, fc7, Mandrake 10.1, mandriva06, suse 9.1, Slackware 10.2, 11.0, 12.0,1,2 (Current)]
Posts: 732

Rep: Reputation: 30
Quote:
Originally Posted by Ajit Gunge View Post
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
login as root once and do :

chmod u+s /sbin/shutdown


now, when you'll do:
/sbin/shutdown (args) it will work as a user.


sticky-bit will be easier in this case.
 
Old 05-18-2009, 01:18 PM   #42
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
^ 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...

Last edited by schneidz; 05-18-2009 at 01:22 PM.
 
Old 05-18-2009, 02:22 PM   #43
itz2000
Member
 
Registered: Jul 2005
Distribution: Fedora fc4, fc7, Mandrake 10.1, mandriva06, suse 9.1, Slackware 10.2, 11.0, 12.0,1,2 (Current)]
Posts: 732

Rep: Reputation: 30
Quote:
Originally Posted by schneidz View Post
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?!
 
Old 05-18-2009, 03:10 PM   #44
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
^ just my own personnal ramblings from working through a mid-afternoon sugar drought in my cubicle.

now that i read it again it seems kinda' simpsons, family guy, athf inspired. maybe i took it from them subconsciously in my half-sleep state.
 
Old 05-18-2009, 06:05 PM   #45
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by Ajit Gunge View Post
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
oh wait there is an error message; it seems like init is not a sudoer.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Cisco Turns Routers Into Linux Application Servers LXer Syndicated Linux News 0 04-10-2008 10:50 PM
RTCW: ET--I get nothing from the servers list Choey Linux - Games 4 11-09-2004 03:42 PM
ET doesn't list servers anymore GT_Onizuka Linux - Games 7 08-09-2004 02:09 PM
Enemy Territory - List of servers for dialup players? furfurdemon666 Linux - Games 1 05-17-2004 10:57 AM
How do add daemons/servers to auto-startup list? bjc Linux - Newbie 2 10-23-2000 04:28 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration