This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
nms-oam/gloam/shell/send_collector.sh

72 lines
1.9 KiB
Bash
Raw Normal View History

#!/bin/bash
basePath="$0"
while [ -h "$basePath" ] ; do
ls=`ls -ld "$basePath"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
basePath="$link"
else
basePath=`dirname "$basePath"`/"$link"
fi
done
basePath=`dirname "$basePath"`
[ -z "$oam_home" ] && oam_home=`cd "$basePath/.." ; pwd`
cd "$oam_home"/shell
#collector 目的目录
collector_dest_path=$oam_home/collector
#collector 源目录
collector_src_path=$oam_home/conf/collector
cd $collector_src_path
#修改configs文件夹下所有.cfg配置文件的pubInfo 中的seqid
while read line;do
eval "$line"
done < $collector_src_path/config
index=1
flag=1
while [ $flag -eq 1 ]; do
key='ip'${index}
value=`eval echo '$'${key}`
OLD_IFS="$IFS"
IFS=","
#ip{id}=ip,user,pwd,name,ethname,sort,isMaster
value_arr=($value)
IFS=$OLD_IFS
ip=${value_arr[0]}
username=${value_arr[1]}
password=${value_arr[2]}
isMaster=${value_arr[6]}
ethname=${value_arr[4]}
if [ -z ${value} ];then
flag=0
else
#是本台机器
isThis=`ifconfig $ethname | head -2 | tail -n 1 | awk '{print $2}'`
echo "index=$index $ip"
if [ "${isThis}" == "${ip}" ];then
mkdir -p $collector_dest_path/
cp -r $collector_src_path/* $collector_dest_path/
chmod +x ${collector_dest_path}/*.sh
#修改config 的seqid
$collector_dest_path/modify_config_seqId.sh
else
$collector_src_path/expect_ssh "$ip" "$username" "$password" "mkdir -p $collector_dest_path"
#其它机器发送脚本,修改配置文件
$collector_src_path/expect_scp_push "$password" ${collector_src_path}/ "$username@$ip:$oam_home"
sleep 1
echo 'expect ssh'
#给脚本执行权限修改config seqId
$collector_src_path/expect_ssh "$ip" "$username" "$password" "chmod +x ${collector_dest_path}/*.sh;$collector_dest_path/modify_config_seqId.sh"
fi
let "index++"
fi
done
#重新返回进入的目录
cd $basePath