LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-30-2014, 02:41 AM   #1
sachin.davra
Member
 
Registered: Jul 2013
Posts: 213

Rep: Reputation: Disabled
run single command on multiple systems


Hi guys,

I am using CentOS6 X86. I have around 100 systems here. I want to know how can i run single command on all system. Is there any tool available or any script? suppose i want to restart a service in all the machines then i would have to login to every machine. Is there any way to complete this job in short time?
 
Old 07-30-2014, 03:08 AM   #2
eklavya
Member
 
Registered: Mar 2013
Posts: 619

Rep: Reputation: 136Reputation: 136
You can write a script for it.Find all IP of your network. Log into the system using ssh then restart the service in each system using loop.
nmap is a program which helps you to detect all IPs of a LAN. Install nmap where you want to run the script.

Code:
#!/bin/bash
IFS=$'\n'
lst=$(nmap -sP 192.168.0.1/24 | awk '/Host/{print $2}')
for i in $lst; do ssh $i service servicename restart; done
It will ask password for each system. To solve this problem save your public key file in each system's .ssh directory as authorized_keys. Now you can log in without password.
You can make it more effective. First check if service is installed on the system, if it is then restart it.

OR

Be advance and install puppet.
Use configuration management tools like puppet or similar one to do jobs like this.
It is always good to use new tools and technologies which are secure and reliable.

Last edited by eklavya; 07-30-2014 at 03:19 AM.
 
Old 07-30-2014, 04:19 AM   #3
sachin.davra
Member
 
Registered: Jul 2013
Posts: 213

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by eklavya View Post
You can write a script for it.Find all IP of your network. Log into the system using ssh then restart the service in each system using loop.
nmap is a program which helps you to detect all IPs of a LAN. Install nmap where you want to run the script.

Code:
#!/bin/bash
IFS=$'\n'
lst=$(nmap -sP 192.168.0.1/24 | awk '/Host/{print $2}')
for i in $lst; do ssh $i service servicename restart; done
It will ask password for each system. To solve this problem save your public key file in each system's .ssh directory as authorized_keys. Now you can log in without password.
You can make it more effective. First check if service is installed on the system, if it is then restart it.

OR

Be advance and install puppet.
Use configuration management tools like puppet or similar one to do jobs like this.
It is always good to use new tools and technologies which are secure and reliable.



Thanks for you reply, i will work on this.
 
Old 07-30-2014, 04:29 AM   #4
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Hi,

clusterssh (or similar) can be used for this. However (as already mentioned) with upwards of 100 hosts I think you should probably look for a proper configuration management solution like puppet or cfengine, especially if you will be needing to make other operations on all those machines in the future.

Cheers,

Evo2
 
Old 08-04-2014, 05:24 AM   #5
sachin.davra
Member
 
Registered: Jul 2013
Posts: 213

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by evo2 View Post
Hi,

clusterssh (or similar) can be used for this. However (as already mentioned) with upwards of 100 hosts I think you should probably look for a proper configuration management solution like puppet or cfengine, especially if you will be needing to make other operations on all those machines in the future.

Cheers,

Evo2

Thanks for your solution. I will try.
 
  


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
[SOLVED] Single command to run multiple commands on ssh knspradeep Linux - Enterprise 5 10-14-2013 08:40 AM
[SOLVED] Run a script on multiple systems shivaa Linux - Newbie 1 10-18-2012 01:17 AM
[SOLVED] NFS export multiple mounted file systems under a single root AdamDaughterson Linux - Server 2 07-28-2009 02:28 PM
How to run multiple process in single command prompt babu198649 Linux - Newbie 7 10-12-2007 09:27 AM
single ext3 journal device multiple journaled file systems? reelwylde Linux - General 4 09-08-2005 04:00 PM


All times are GMT -5. The time now is 04:45 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration