LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 11-25-2011, 03:53 AM   #1
hhh123
Member
 
Registered: Jul 2009
Location: /
Distribution: centos
Posts: 47

Rep: Reputation: 1
Run command on multiple server/node.


Hi All,

I am using centos 6, and i have more than 100+ server to execute or to deploy some application on it.Is there any solution in open source solution for the same ??

Thank You..
 
Old 11-25-2011, 04:07 AM   #2
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 211Reputation: 211Reputation: 211
ssh would be fine if you've already setup some authentication other than password:

Code:
for x in `seq 0 255`; do
  for y in `seq 0 255`; do
    ssh root@192.168.$x.$y 'yum install program'
  done
done
 
Old 11-25-2011, 04:34 AM   #3
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
I fully agree with jhwilliams.

If you have a lot of machines to connect to, you might wish to do the installations in parallel, instead of one after the other. Something like the following should prove useful:

Code:
#!/bin/bash

# File containing hostnames for all the servers; one per line.
serverlist=~/.server-list
[ -r "$serverlist" ] || exit 1

# Create a safe, autodeleted temporary directory
work=$(mktemp -d) || exit $?
trap "rm -rf '$work'" EXIT

# List of hosts to connect to
hosts=()
while read host dummy ; do

    # Ignore comments
    host="${host%%;*}"
    host="${host%%#*}"
    host="${host%%/*}"
    [ -n "$host" ] || continue

    # Add host to hosts used
    hosts=("${hosts[@]}" "$host")
done < "$serverlist" || exit $?

# None?
[ ${#hosts[@]} -gt 0 ] || exit 0

# Run remote commands in parallel on each host.
for host in "${hosts[@]}" ; do
    ( exec </dev/null >"$work/$host.out" 2>"$work/$host.err"
      echo -n "Started "
      date
      ssh "$host" "$@" && echo "[OK]" || echo "[Error $?]"
      echo -n "Finished "
      date
    ) &
done

# Wait for all to complete
wait

# Output the summary of all commands
for host in "${hosts[@]}" ; do
    echo "Output from $host:"
    sed -e 's|^|\t|' "$work/$host.out"
    echo ""
    if [ -s "$work/$host.err" ]; then
        echo "Errors from $host:"
        sed -e 's|^|\t|' "$work/$host.err"
    else
        echo "No error messages."
    fi
    echo ""
    echo "========================================"
fi
 
Old 11-25-2011, 10:12 AM   #4
hhh123
Member
 
Registered: Jul 2009
Location: /
Distribution: centos
Posts: 47

Original Poster
Rep: Reputation: 1
HI,

I got something new.....i got pdsh (http://sourceforge.net/projects/pdsh/) and clusterssh(http://sourceforge.net/projects/clusterssh/), clustershell(http://sourceforge.net/projects/clustershell/).Just have a look.
 
  


Reply



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
How to run multiple X server in single terminal in linux greensuman Linux - Software 3 12-12-2010 07:34 AM
RHEL5 2-Node Apache Cluster w/multiple floating IPs Linville79 Linux - Enterprise 2 04-13-2010 04:47 PM
[SOLVED] Can one know from which server a particular command was run in a network? Ajit Gunge Linux - Newbie 4 05-20-2009 04:28 AM
How to run multiple process in single command prompt babu198649 Linux - Newbie 7 10-12-2007 08:27 AM
multiple node ping hockeyman_102 Linux - Networking 3 09-13-2006 02:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 06:19 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