Shell实现自动更新目录名称与文件中版本号信息与时间戳
2015-12-19 19:11
591 查看
背景:
修改如下样例目录下所有目录的版本号信息与时间戳;
修改如下样例文件中的版本号信息与时间戳;
样例目录:
样例文件信息:
实现Shell脚本:
执行结果:
修改如下样例目录下所有目录的版本号信息与时间戳;
修改如下样例文件中的版本号信息与时间戳;
样例目录:
$ find template_patch_dir/ template_patch_dir/ template_patch_dir/ONIP_SNE_V300R002C80CP1006_SUSE11_D2015-12-10 template_patch_dir/ONIP_SNE_V300R002C80CP1006_SUSE11_D2015-12-10/modules template_patch_dir/ONIP_SNE_V300R002C80CP1006_SUSE11_D2015-12-10/package.xml template_patch_dir/ONIP_SNE_V300R002C80CP1006_SUSE10_D2015-12-10 template_patch_dir/ONIP_SNE_V300R002C80CP1006_SUSE10_D2015-12-10/modules template_patch_dir/ONIP_SNE_V300R002C80CP1006_SUSE10_D2015-12-10/package.xml
样例文件信息:
$ cat template_patch_dir/ONIP_SNE_V300R002C80CP1006_SUSE11_D2015-12-10/package.xml version="V300R002C80CP1006" name="ONIP_SNE_V300R002C80CP1006_SUSE11_D2015-12-10.tar.gz"
实现Shell脚本:
#!/bin/sh template_version="V300R002C80CP1006" template_date="2015-12-10" ##make os type pkg function make_os_type_pkg { cd ${current_path} os_type=$1 old_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.xml sed -i "s#${template_date}#`date +%Y-%m-%d`#" package.xml tar 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 1 fi new_version=$1 ####copy example pkg, not modify the example dir rm -rf new_patch_dir cp -r template_patch_dir new_patch_dir cd temp_dir current_path=`pwd` make_os_type_pkg SUSE10 make_os_type_pkg SUSE11 } main $@
执行结果:
$ ./make_patch_pkg.sh V300R002C30CP1011B06 [xbh@bogon xbh]$ ls make_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-19 new_patch_dir/ONIP_SNE_V300R002C30CP1011B06_SUSE11_D2015-12-19/ONIP_SNE_V300R002C30CP1011B06_SUSE11_D2015-12-19.tar.gz new_patch_dir/ONIP_SNE_V300R002C30CP1011B06_SUSE10_D2015-12-19 new_patch_dir/ONIP_SNE_V300R002C30CP1011B06_SUSE10_D2015-12-19/ONIP_SNE_V300R002C30CP1011B06_SUSE10_D2015-12-19.tar.gz
相关文章推荐
- Linux shell 之 awk的用法
- Powershell-Exchange:设置分层通讯薄中通讯组的优先级
- Powershell-Exchange:如何确定用户是否设置了邮件流转发
- shell统计平均值和BX求值的问题
- adb shell 打开应用程序
- Bash关闭输出(关闭正确、错误输出)
- shell 中的连接符(并且&&、与;、或||)
- Bash算术计算
- Bash函数使用
- Bash从路径中获取文件名
- Bash中的$符号
- 过生日,也要学学哈,这次是SHELL的GETOPTS
- shell 变量
- Bash判断是否是root
- shell字符串处理
- Bash循环分类介绍
- Bash判断文件夹(目录)是否存在
- Bash判断文件是否存在
- Bash中的数组
- shell 入门