64 lines
1.6 KiB
Bash
64 lines
1.6 KiB
Bash
#!/bin/bash
|
|
basePath=$(cd `dirname $0`; pwd)
|
|
cd ${basePath}
|
|
|
|
echo "$basePath"
|
|
#处理device_config 脚本
|
|
if [ ! -f '/usr/local/bin/device_config' ];then
|
|
cp "$basePath"/device_config /usr/local/bin
|
|
if [ $? = 0 ];then
|
|
chmod +x /usr/local/bin/device_config
|
|
fi
|
|
fi
|
|
|
|
|
|
#修改configs文件夹下所有.cfg配置文件的pubInfo 中的seqid
|
|
while read line;do
|
|
eval "$line"
|
|
done < 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}'`
|
|
if [ $isThis = "$ip" ]; then
|
|
for file in ./configs/*.cfg
|
|
do
|
|
#修改seqid
|
|
sed -i "s/^pubInfo=[^,]*/pubInfo=$index/g" $file
|
|
echo "modfiy $ip $file $index"
|
|
done
|
|
if [ $isMaster -eq 1 ];then
|
|
if [[ -f ${basePath}"/merge.sh" && -z "$(grep "$basePath/merge.sh" /var/spool/cron/root |grep -v 'grep' 2>/dev/null)" ]];then
|
|
echo "*/1 * * * * $basePath/merge.sh">>/var/spool/cron/root
|
|
echo "isMaster add merge.sh crontab"
|
|
fi
|
|
fi
|
|
|
|
#检查是否开启定时任务
|
|
if [ -z "$(grep $basePath/getSingleMacInfo.sh /var/spool/cron/root | grep -v 'grep' 2>/dev/null)" ];then
|
|
echo "*/5 * * * * $basePath/getSingleMacInfo.sh" >>/var/spool/cron/root
|
|
echo "$ip add getSingleMacInfo.sh crontab"
|
|
fi
|
|
flag=0
|
|
fi
|
|
let "index++"
|
|
fi
|
|
done
|