美文网首页
2020-03-30:对于shell脚本中对特定目录下的特定文件

2020-03-30:对于shell脚本中对特定目录下的特定文件

作者: 烂笔头2020 | 来源:发表于2020-03-30 16:50 被阅读0次

这里用到了shell脚本中的条件语句,因为时间比较紧,所以先不做详细的展开学习,先给自己留一下课后作业:

1、判断文件目录是否存在的参数 -d
2、[ ] 和 [[ ]] 的区别和注意事项
3、if 语句的表达注意事项

放一下写的代码

#!/bin/bash
#第一步:对/data/columns目录下的前一日目录进行判断,如果目录存在,则上传到hdfs,不存在目录则输出文件目录不存在
#每日定时把/data/columns目录下的内容进行文件分类上传到hdfs指定目录下
the_year=$1
the_month=$2
the_day=$3

#文件存放的目录
linux_dir=/data/columns/"$the_year$the_month$the_day"/

#判断目录是否存在
if [ ! -d "$linux_dir" ];then
    echo " "$linux_dir"目录不存在! "
fi

#目录文件存在则上传到hdfs
if [ -d "$linux_dir" ]; then
    #上传目录
    hdfs_category_dir=/test/lee/gdfs/"$the_year$the_month$the_day"/Columns/
    hdfs_asset_dir=/test/lee/gdfs/"$the_year$the_month$the_day"/ColumnsResAsset/
    hdfs_series_dir=/test/lee/gdfs/"$the_year$the_month$the_day"/SeriesResChild/
    #创建目录
    /usr/local/hadoop/hadoop-2.8.1/bin/hadoop fs -mkdir /test/lee/gdfs/"$the_year$the_month$the_day"
    /usr/local/hadoop/hadoop-2.8.1/bin/hadoop fs -mkdir /test/lee/gdfs/"$the_year$the_month$the_day"/Columns
    /usr/local/hadoop/hadoop-2.8.1/bin/hadoop fs -mkdir /test/lee/gdfs/"$the_year$the_month$the_day"/ColumnsResAsset
    /usr/local/hadoop/hadoop-2.8.1/bin/hadoop fs -mkdir /test/lee/gdfs/"$the_year$the_month$the_day"/SeriesResChild
    
    #读取目录
    ls $linux_dir | while read fileName
    do
        #上传栏目架构表
        if [[ "$fileName" == Columns_* ]];then
            /usr/local/hadoop/hadoop-2.8.1/bin/hadoop fs -put $linux_dir$fileName $hdfs_category_dir$fileName
        fi
        
        #上传媒资信息表
        if [[ "$fileName" == ColumnsResAsset_* ]];then
            /usr/local/hadoop/hadoop-2.8.1/bin/hadoop fs -put $linux_dir$fileName $hdfs_asset_dir$fileName
        fi
        
        #上传子集集合关联表
        if [[ "$fileName" == SeriesResChild_* ]];then
            /usr/local/hadoop/hadoop-2.8.1/bin/hadoop fs -put $linux_dir$fileName $hdfs_series_dir$fileName
        fi
        
    done    
fi

相关文章

  • 2020-03-30:对于shell脚本中对特定目录下的特定文件

    这里用到了shell脚本中的条件语句,因为时间比较紧,所以先不做详细的展开学习,先给自己留一下课后作业: 1、判断...

  • shell命令之find

    在导出库给其他同学使用的时候,有时候需要导出特定目录下所有特定文件。在OSX中可以很方便用shell脚本实现这样的...

  • 2.13 批量重命名和移动

    《Linux Shell 脚本攻略(第 2 版)》读书笔记 用特定的格式重命名当前目录下的图像文件,最简单的方法是...

  • 批量修改目录文件名

    脚本可以遍历目录中的特定文件,然后替换、修改特定的字符串。

  • 第一个shell脚本

    第一个shell脚本 1、关于#! 在脚本开头的 sha-bang (#!) 是告诉系统这个文件是由特定命令解释器...

  • NDK<第九篇>:Shell脚本

    shell 是一种脚本语言。脚本:本质是一个文件,文件里面存放的是 特定格式的指令,系统可以使用脚本解析器 翻译或...

  • find 查找命令 + 模糊匹配

    1、在当前目录下搜索指定文件: 2、在当前目录下模糊搜索文件: 3、在当前目录下搜索特定属性的文件: 4、在当前目...

  • 2.9 排序、唯一与重复

    《Linux Shell 脚本攻略(第 2 版)》读书笔记 sort命令既可以从特定的文件,也可以从 stdin ...

  • 3.2 生成任意大小的文件

    《Linux Shell 脚本攻略(第 2 版)》读书笔记 创建特定大小的大文件最简单的方法就是利用 dd 命令。...

  • Matlab批处理文件的一些笔记

    1.获取特定文件目录下文件的一个小脚本,以cell格式存储文件名: function filename=batch...

网友评论

      本文标题:2020-03-30:对于shell脚本中对特定目录下的特定文件

      本文链接:https://www.haomeiwen.com/subject/pxivuhtx.html