[root@bigdata01 ~/install]# vim change-yarn-site.sh
#!bin/bash
#此脚本对大数据集群所有节点的yarn-site.xml文件根据集群配置自动更改对应配置。
HOST_LIST=`grep 'bigdata' /etc/hosts |awk '{print $2}'`
conf_dir=/data/software/hadoop/etc/hadoop/yarn-site.xml
vcores=`lscpu |awk 'NR==4{print $2}'`
nodemanager_mb=`free -h |awk 'NR==2{print $2/10*8*1024}'`
#${HOST_LIST[@]} $@的用法,取出脚本所有参数,带双引号识别为一个整体,不带双引号以空格为分隔,用于循环数组中
scheduler_mb=`for i in ${HOST_LIST[@]}
do
ssh $i -p 22 -a "free -h" |awk 'NR==2{print $2/10*8*1024}'
done |sort -rn |head -1 |cut -d '.' -f1`
sed -i "/nodemanager/N;s#8#$vcores#g" $conf_dir
sed -i "/nodemanager/N;s#12288#$nodemanager_mb#g" $conf_dir
sed -i "/scheduler/N;s#8#$vcores#g" $conf_dir
sed -i "/scheduler/N;s#9600#$scheduler_mb#g" $conf_dir
#cut命令使用
[root@bigdata01 /server/scripts]# echo "3.1415926" |cut -d '.' -f1
3
[root@bigdata01 /server/scripts]# echo "3.1415926" |cut -d '.' -f2
1415926
标签:shell,conf,配置文件,cut,案例,sed,scheduler,print,dir
From: https://www.cnblogs.com/anslinux/p/17154419.html