Shell实现自动更新目录名称与文件中版本号信息与时间戳

来源:互联网 发布:金蝶会计软件 编辑:程序博客网 时间:2024/05/17 23:53
背景:
修改如下样例目录下所有目录的版本号信息与时间戳;

修改如下样例文件中的版本号信息与时间戳;


样例目录:

$ find template_patch_dir/template_patch_dir/template_patch_dir/ONIP_SNE_V300R002C80CP1006_SUSE11_D2015-12-10template_patch_dir/ONIP_SNE_V300R002C80CP1006_SUSE11_D2015-12-10/modulestemplate_patch_dir/ONIP_SNE_V300R002C80CP1006_SUSE11_D2015-12-10/package.xmltemplate_patch_dir/ONIP_SNE_V300R002C80CP1006_SUSE10_D2015-12-10template_patch_dir/ONIP_SNE_V300R002C80CP1006_SUSE10_D2015-12-10/modulestemplate_patch_dir/ONIP_SNE_V300R002C80CP1006_SUSE10_D2015-12-10/package.xml

样例文件信息:

$ cat template_patch_dir/ONIP_SNE_V300R002C80CP1006_SUSE11_D2015-12-10/package.xmlversion="V300R002C80CP1006"name="ONIP_SNE_V300R002C80CP1006_SUSE11_D2015-12-10.tar.gz"

实现Shell脚本:

#!/bin/shtemplate_version="V300R002C80CP1006"template_date="2015-12-10"##make os type pkgfunction make_os_type_pkg{    cd ${current_path}    os_type=$1old_dirname=`ls | grep ${os_type}`new_dirname="ONIP_SNE_${new_version}_${os_type}_D`date +%Y-%m-%d`"mv ${old_dirname} ${new_dirname}cd *${os_type}*sed -i "s#${template_version}#${new_version}#g" package.xmlsed -i "s#${template_date}#`date +%Y-%m-%d`#" package.xmltar zcf ${new_dirname}.tar.gz *###delete dir and file name not contents '.gz'ls | grep -Fv '.gz' | xargs rm -rf }function main{if [ $# -ne  1 ];then echo "make_patch_pkg.sh new_version_number" exit 1finew_version=$1####copy example pkg, not modify the example dirrm -rf new_patch_dircp -r template_patch_dir new_patch_dir cd temp_dir current_path=`pwd`make_os_type_pkg SUSE10make_os_type_pkg SUSE11}main $@

执行结果:

$ ./make_patch_pkg.sh  V300R002C30CP1011B06[xbh@bogon xbh]$ lsmake_patch_pkg.sh  new_patch_dir  template_patch_dir[xbh@bogon xbh]$ find new_patch_dir/new_patch_dir/new_patch_dir/ONIP_SNE_V300R002C30CP1011B06_SUSE11_D2015-12-19new_patch_dir/ONIP_SNE_V300R002C30CP1011B06_SUSE11_D2015-12-19/ONIP_SNE_V300R002C30CP1011B06_SUSE11_D2015-12-19.tar.gznew_patch_dir/ONIP_SNE_V300R002C30CP1011B06_SUSE10_D2015-12-19new_patch_dir/ONIP_SNE_V300R002C30CP1011B06_SUSE10_D2015-12-19/ONIP_SNE_V300R002C30CP1011B06_SUSE10_D2015-12-19.tar.gz




0 0
原创粉丝点击