自动实现Hadoop Decommission shell脚本版
#!/bin/bashconf_dir=/opt/hadoop-2.6.0/etc/hadoop/
backup_dir=/opt/hadoop-2.6.0/etc/hadoop/BAK/
exclude_host=$1
exclude_file=$2
function usage() {
echo -e "usage: $0 exclude file\nplease input the parameter ---- mapred-exclude or hdfs-exclude"
}
if [ $# -ne 2 ] ;then
usage
exit 1
elif [ "$exclude_file" != "mapred-exclude" -a "$exclude_file" != "hdfs-exclude" ];then
usage
exit 1
fi
#if [ -d /apache/hadoop/conf ] ;then
# cd /apache/hadoop/conf
#else
# echo "dir /apache/hadoop/conf doesnot exist , please check!"
# exit 3
#fi
[ ! -d ${backup_dir} ] && mkdir ${backup_dir}
# backup exclude file
cp "${conf_dir}${exclude_file}" ${backup_dir}"${exclude_file}"-`date +%F.%H.%M.%S`
# append hosts to exclude file
grep ${exclude_host} "${conf_dir}${exclude_file}" >/dev/null 2>&1
retval=$?
if [ $retval -ne 0 ];then
echo ${exclude_host} >> "${conf_dir}${exclude_file}"
else
echo "duplicated host: ${exclude_host}"
fi
页:
[1]