Fedora Linux Support Community & Resources Center
  #1  
Old 28th July 2010, 11:00 PM
twohot's Avatar
twohot Offline
Registered User
 
Join Date: Jun 2009
Location: 9ja://coalcity
Posts: 259
linuxfedorafirefox
remote shutdown

I need to be able to remotely shut down 2-or-more PCs from one Laptop on a LAN network. How should I go about it? (meanwhile, the network is pinging fine ... )
Reply With Quote
  #2  
Old 28th July 2010, 11:25 PM
bbfuller Offline
Registered User
 
Join Date: Jun 2005
Location: UK
Posts: 4,415
linuxopera
Re: remote shutdown

Hello twohot

The way I do it here is to use ssh.

In a terminal window:

Code:
ssh <network identity of remote machine>
That demands the password of the user you are using and logging in as. It assumes you have the same user identity/password on both machines.

Then:

Code:
su -
to gain root control of the remote machine and finally:

Code:
shutdown -h now
will shut the remote machine down.

Code:
shutdown -r now
will reboot it.

Hope that helps.
Reply With Quote
  #3  
Old 29th July 2010, 01:52 AM
twohot's Avatar
twohot Offline
Registered User
 
Join Date: Jun 2009
Location: 9ja://coalcity
Posts: 259
linuxfedorafirefox
Re: remote shutdown

Well, since the PCs are not physically far from each other (less than 2 metres) and are few in number, it would take less time to reach out and press the power button (followed by "enter"). I was thinking of something more automated ... unless there is a way to issue the ssh & shutdown commands to all PCs, simultaneously.
Reply With Quote
  #4  
Old 29th July 2010, 02:02 AM
scott32746 Offline
Registered User
 
Join Date: Jun 2007
Location: Lake Mary, Florida
Age: 53
Posts: 1,088
windows_xp_2003firefox
Re: remote shutdown

Hello,
You can, but it would require ssh with root ID And that is not a good idea
Could setup a cron job to shutdown the servers/PC
Reply With Quote
  #5  
Old 29th July 2010, 11:04 AM
aesir's Avatar
aesir Offline
Registered User
 
Join Date: Nov 2008
Location: ~
Age: 31
Posts: 175
linuxfedorafirefox
Re: remote shutdown

Setting up an RSA public key you can avoid typing the password (beware that this has security implications in case someone get access to your private key).

Then on the remote machines you can set sudo to allow your non-root user tu run shutdown without password, with something like this in /etc/sudoers

Code:
user  ALL=NOPASSWD: /sbin/shutdown
To shutdown all the machines you will just run
Code:
for ip in 192.168.1.1 192.168.1.2 192.168.1.3; do
 ssh user@$ip -i ~/.ssh/id_rsa "sudo shutdown -h now"
done
Reply With Quote
  #6  
Old 30th July 2010, 10:57 AM
twohot's Avatar
twohot Offline
Registered User
 
Join Date: Jun 2009
Location: 9ja://coalcity
Posts: 259
linuxfedorafirefox
Re: remote shutdown

Quote:
Originally Posted by aesir View Post
Setting up an RSA public key you can avoid typing the password (beware that this has security implications in case someone get access to your private key).

Then on the remote machines you can set sudo to allow your non-root user tu run shutdown without password, with something like this in /etc/sudoers

Code:
user  ALL=NOPASSWD: /sbin/shutdown
To shutdown all the machines you will just run
Code:
for ip in 192.168.1.1 192.168.1.2 192.168.1.3; do
 ssh user@$ip -i ~/.ssh/id_rsa "sudo shutdown -h now"
done
Interesting. I'll check that out.
Wondering what the first line of the "for" statement will look like for a larger network.

---------- Post added at 10:57 AM CDT ---------- Previous post was at 10:52 AM CDT ----------

Quote:
Originally Posted by scott32746 View Post
Hello,
You can, but it would require ssh with root ID And that is not a good idea
Could setup a cron job to shutdown the servers/PC
... that is, if there is a way to execute a particular job at request. In that case, one should be able to access cron jobs remotely from a server. How is that done? It will be interesting to know how to schedule a shutdown at idle time ... this is one task no one has addressed to my satisfaction.
Reply With Quote
  #7  
Old 30th July 2010, 01:05 PM
aesir's Avatar
aesir Offline
Registered User
 
Join Date: Nov 2008
Location: ~
Age: 31
Posts: 175
linuxfedorafirefox
Re: remote shutdown

Quote:
Originally Posted by twohot View Post
Interesting. I'll check that out.
Wondering what the first line of the "for" statement will look like for a larger network.
to run on the whole 192.168.0.0/16 block
Code:
for c in `seq 0 255`; do 
 for d in `seq 0 255`; do 
  ip="192.168.$c.$d";
  ...
 done
done
if you have a hard-to-generate pattern you can put the list of ip in a text file and read from it
Code:
while read ip; do
 ...
done < iplist
Quote:
Originally Posted by twohot
... that is, if there is a way to execute a particular job at request. In that case, one should be able to access cron jobs remotely from a server. How is that done? It will be interesting to know how to schedule a shutdown at idle time ... this is one task no one has addressed to my satisfaction.
I wonder why you would remotely activate a cron job, which as the name suggest is supposed to automatically run on scheduled times; and it would be harder to implement than just running the command with ssh.

To shutdown at idle time you can create a cron job with a script that runs "shutdow -h now" when some condition is true, for example
Code:
avgload=$(echo "scale=0; `cat /proc/loadavg | cut -d " " -f 3`/0.01" | bc)
[ $avgload -le 30 ] && shutdown -h now
Reply With Quote
  #8  
Old 30th July 2010, 05:44 PM
twohot's Avatar
twohot Offline
Registered User
 
Join Date: Jun 2009
Location: 9ja://coalcity
Posts: 259
linuxfedorafirefox
Thumbs up Re: remote shutdown

Very Coool

It is a good time to learn bash tricks.
Thanks ... for helping a scripting novice. Much appreciated! I'll decode at my pace ... and report back when I hit the wall
Reply With Quote
  #9  
Old 19th September 2010, 07:45 AM
twohot's Avatar
twohot Offline
Registered User
 
Join Date: Jun 2009
Location: 9ja://coalcity
Posts: 259
windows_7firefox
Re: remote shutdown

Hi People!

I finally gave your suggestions a critical look (I had little or no bash experience before). I was able to extract bits of code to construct what I needed. Here are a few of my observations:

Aesir's code ...
Code:
for ip in 192.168.1.1 192.168.1.2 192.168.1.3; do
 ssh user@$ip -i ~/.ssh/id_rsa "sudo shutdown -h now"
done
... Is lacking a "-t" switch for the ssh which removes the need for tty. Sudo requires tty over ssh by default, forcing the client to type passwords -- which is what we don't want. Again, for a proper RSA (keys) authentication setup the "-i" switch is not necessary after using ssh-agent. Apart from those, this is cool. Thanks Aesir!
I found that iterating through a large network with "for-do-done" loop makes for a slow execution especially if some hosts are unavailable (negotiation time lapses).

SO, .... I'm using:
Code:
while read ip; do
 ...
done < iplist

Its fast for a network of 10-30 PCs
Reply With Quote
  #10  
Old 25th September 2010, 09:44 PM
assen Offline
Registered User
 
Join Date: Oct 2008
Posts: 498
linuxfedorafirefox
Re: remote shutdown

Hi,

A different approach: install apcupsd and run it in slave mode on the desired servers. Set up an apcupsd in master mode on your workstation. Then use the apcupsd to shut down the remote servers.

Or, more broadly speaking, any RPC client-server should do your job.

WWell,
Reply With Quote
  #11  
Old 27th September 2010, 12:16 PM
vertextao's Avatar
vertextao Offline
Registered User
 
Join Date: Sep 2010
Location: China
Posts: 75
linuxchrome
Re: remote shutdown

Quote:
Originally Posted by aesir View Post
Setting up an RSA public key you can avoid typing the password (beware that this has security implications in case someone get access to your private key).

Then on the remote machines you can set sudo to allow your non-root user tu run shutdown without password, with something like this in /etc/sudoers

Code:
user  ALL=NOPASSWD: /sbin/shutdown
To shutdown all the machines you will just run
Code:
for ip in 192.168.1.1 192.168.1.2 192.168.1.3; do
 ssh user@$ip -i ~/.ssh/id_rsa "sudo shutdown -h now"
done
How interesting!^^^
Reply With Quote
Reply

Tags
remote, shutdown

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Shutdown button through remote sessions: dangerous and stupid cuban_cigar Reviews, Rants & Things That Make You Scream 1 26th May 2010 08:06 PM
Why do shutdown -h and shutdown -r behave so differently? jlixfeld Using Fedora 1 18th March 2008 06:00 PM
F8 : No Shutdown in menu, Login Screen is weird, Can't Shutdown only reboot megat Using Fedora 5 19th November 2007 12:00 PM
Shutdown doesn't shutdown completely, not ACPI related... MasterC Using Fedora 2 12th February 2007 07:07 PM
How to hide FC6 shutdown messages or use shutdown spash renjoyhenry Using Fedora 0 5th November 2006 06:09 AM


Current GMT-time: 09:17 (Tuesday, 26-09-2017)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat