In a cluster tool to synchronize files and shell commands -02

CmdSync.sh

[root@localhost sync]# cat CmdSync.sh
#!/bin/bash


#同步集群命令

CONF=../config

PraserConf(){
    num=`sed -n -e '/^\['$1'\]/=' $CONF`
    let temp=num+1
    sed -n ''$temp'p' $CONF
}

nodes_str=`PraserConf nodes`
old_ifs="$IFS"
IFS=","
nodes=($nodes_str)


CmdSync(){
    cmd=$1
    echo $1
    for node in ${nodes[*]}
    do  
        echo -e "\e[32m******$node******\e[0m"
        ssh root@$node "$cmd"
        if [ $? -eq 0 ]
        then
            echo cmd successful
        fi
    done
}

CmdSync "$1"

 

FileSync.sh:

[the root @ localhost Sync] FileSync.sh CAT #
#! / bin / the bash


# synchronize the cluster files
# absolute path into the reference file

CONF = .. / config

PraserConf () {
    NUM = -n -e `Sed '/ ^ \ [ '. 1 $' \] / = '$ CONF`
    the let TEMP = NUM +. 1
    Sed -n' 'temp'p $' $ CONF
}

nodes_str = `PraserConf nodes`
old_ifs =" $ the IFS "
the IFS =", "
Nodes = ($ nodes_str)


syncfile () {
    base_dir = $. 1
    echo $. 1
    base_dir = `echo $ base_dir | awk -F" / " '{for (I =. 1; I <= of NF-. 1; I ++) the printf ("% S / " , $ I)} ' `
    echo $ base_dir
    for Node Nodes in $ {[*]}
    do
        IP addr | grep $ Node> / dev / null 2> &1
        if [ $? -ne 0 ]
        then
            -r $ 1 root @ scp the Node $: $ base_dir
            #> / dev / null 2> & 1
            IF [$ 1 -eq?]
            the then
                SSH root @ $ the Node "mkdir -p $ base_dir"
                scp -r $ 1 root @ $ the Node: $ base_dir
                #> / dev / null 2> &. 1
            Fi
        Fi
    DONE
}


# path Switch
# converts path is absolute
tran_path () {
    IF [[ "$. 1" = ~ ^ /]]
    the then
        IF [[ "$. 1" = ~ / $]]
        the then
            base_dir echo $ = `. 1 | awk -F" / " '{for (I = 2; I <= of NF-. 1; I ++) the printf (" /% S ", $ I)}'`
            Echo $ base_dir
        else
            echo $ 1
        fi
    elif [[ -d $1 ]]||[[ -z $1 ]]
    then
        path=`pwd`/$1
        cd $path >/dev/null
        real_path=`pwd`
        echo $real_path
    else
        path=`pwd`/$1
        base_dir=`echo $path|awk -F"/" '{for (i=1;i<=NF-1;i++) printf("%s/",$i)}'`
        cd $base_dir >/dev/null
        real_path=`pwd`/`basename $1`
        cd - >/dev/null
        echo $real_path
    fi
}

#tran_path $1
SyncFile `tran_path $1`

Guess you like

Origin www.cnblogs.com/wuchy/p/12177395.html