目录
问题
实例
问:
想在bash脚本中修改改安装Oracle软件的响应文件db_install.rsp。
相关参数有:
SELECTED_LANGUAGES=en,zh_CN,zh_TW
ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
ORACLE_BASE=/u01/app/oracle
oracle.install.db.InstallEdition=EE
原文本只含有“参数=”,如何在bash中批量赋值给对应参数?
答:
sed -i 's/^参数名=.*/参数名=新值/' 配置文件路径
实例
将配置文件中的ms_cluster_type = async+posix改为ms_cluster_type = async+rdma 或者反过来:
方法1:匹配修改
方法2:删除原配置行,添加新配置行
#ps -ef | grep fio | grep -v grep | awk '{print $2}' | xargs kill -s 9
CONF_PATH='/etc/ceph/ceph.conf'
if [ -z $1 ] ; then
echo "******************"
echo "Please input arg:"
echo "******************"
echo "-----------------------------------"
echo "p or P:change ceph conf to posix"
echo "r or R:change ceph conf to rdma"
echo "-----------------------------------"
exitelse
TYPE=$1
fi
case ${TYPE} in
p|P)sed -i 's/^ms_cluster_type =.*/ms_cluster_type = async+posix/' ${CONF_PATH}
cat ${CONF_PATH} | grep 'ms_cluster_type'if false; then
sed -i '/ms_cluster_type = async+posix/d' ${CONF_PATH} #delete line
sed -i '/ms_cluster_type = async+rdma/d' ${CONF_PATH} #delete linesed -i '/ms_public_type = async+posix/a\ms_cluster_type = async+posix' ${CONF_PATH} #add line after 'ms_public_type = async+posix'
sed -i '/ms_public_type = async+posix/a\#ms_cluster_type = async+rdma' ${CONF_PATH} #add line after 'ms_public_type = async+posix'
fi;;
r|R)sed -i 's/^ms_cluster_type =.*/ms_cluster_type = async+rdma/' ${CONF_PATH}
cat ${CONF_PATH} | grep 'ms_cluster_type'if false; then
sed -i '/ms_cluster_type = async+posix/d' ${CONF_PATH} #delete line
sed -i '/ms_cluster_type = async+rdma/d' ${CONF_PATH} #delete linesed -i '/ms_public_type = async+posix/a\#ms_cluster_type = async+posix' ${CONF_PATH} #add line after 'ms_public_type = async+posix'
sed -i '/ms_public_type = async+posix/a\ms_cluster_type = async+rdma' ${CONF_PATH} #add line after 'ms_public_type = async+posix'
fi
;;
*)
esac