替换工程shell


项目使用新的规范,需要将之前的工程重新修改,写一shell脚本,输入老工程名,新工程名来替换里面需要替换的部分


#!/bin/bash


if [ $# -ne 2 ] ;
then 
  echo "please enter an old project name and a new project name!"
else
  
  old_name=$1
  new_name=$2
  len=$(expr length "${new_name}")  
  let "len = len - 3"
  pro_name=$(echo ${new_name}|cut -c1-$len)
  workflow_name=$(echo ${new_name}|cut -c1-$len)"-wf"  
  
  echo "DEBUG: old name is: "${old_name}", new name is: "${new_name}", workflow name is: "${workflow_name}
  
  echo "DEBUG: rename project name..."
  mv ${old_name} ${new_name}
  
  cd ${new_name}
  
  echo "DEBUG: rename properties"
  mv ${old_name}.properties ${new_name}.properties
  sed -i "s:bd-wh/bd-wh-common:bd-wh-common-cd:g"  ${new_name}.properties
  sed -i "s:bd-wh/${old_name}:${new_name}:g" ${new_name}.properties
  
  echo "DEBUG: replace runjob.sh"
  sed -i "s:bd-wh/bd-wh-common:bd-wh-common-cd:g"  runJob.sh
  sed -i "s:bd-wh/${old_name}:${new_name}:g" runJob.sh
  sed -i "s:${old_name}.properties:${new_name}.properties:g" runJob.sh
  
  echo "DEBUG: replace coordinator.xml"
  sed -i "s:${old_name}-cd:${new_name}:g" coordinator.xml
  sed -i "s:${old_name}.dataset:${new_name}-dataset:g" coordinator.xml
  
  datasets_begin=$(grep  -n  "<datasets>"   coordinator.xml  | cut  -d  ":"  -f  1)
  datasets_end=$(grep  -n  "</datasets>"   coordinator.xml  | cut  -d  ":"  -f  1)
  let "dataset_begin = datasets_begin + 1"
  let "dataset_end = datasets_end - 1"
  echo "DEBUG: delete dataset dataset_begin: "${dataset_begin}", dataset_end: "${dataset_end}
  sed -i ${dataset_begin},${dataset_end}d coordinator.xml


  common_dataset='\ \ \ \ <include>${hdfs_address_prefix}/bd-wh-common-cd/datasets.xml</include>'
  sed -i "${datasets_begin}a${common_dataset}" coordinator.xml
  
  echo "DEBUG: replace workflow.xml"
  sed -i "s:${old_name}-wf:${workflow_name}:g" workflow*.xml
  sed -i "s:${old_name}:${pro_name}:g" workflow*.xml
  
  echo "DEBUG: replace putShell.sh"
  sed -i "s:bd-wh/::g" putShell.sh
  
  reRunJob=reRunJob.sh
  if [ -f "${reRunJob}" ]; then
    echo "DEBUG: replace reRunJob.sh"
    sed -i "s:bd-wh/${old_name}/${old_name}:${new_name}/${new_name}:g" ${reRunJob}
  fi
  
  echo "DEBUG: dos2unix ..."
  dos2unix *.*
  
  echo "DEBUG: checking ..."
  grep -ER "bd-wh|bd-wh-common|${old_name}" .
  echo "DEBUG: checked."
  
  #sed -i "s:bd-wh/${old_name}:${new_name}:g" `grep 'bd-wh.${old_name}' -rl ${cpath}`

fi


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值