Bash 脚本将 csv 保存在数组中并搜索字符串的一部分

Bash script save csv in array and search for part of string

编辑我的脚本后,我想很快解释一下我想做什么:

  1. 检查文件夹中是否有文件
  2. 查看文件名的开头
  3. 搜索不到 1 小时的文件
  4. 获取文件并执行 sqlldr ..如果成功将文件移动到其他文件夹...如果没有发送邮件

这是我的脚本,有人可以告诉我这是否可行吗?我不确定语法,也不确定 nr. 3和4.发送邮件是这样的

    #!/bin/sh

    #check if files are in folder
    declare -a arrCSV   #create array
    for file in *.csv
    do
    arrCSV=("${CSV[@]}" "$file")
    done

    shopt -s nullglob
    for file in read*.csv; do
    #run on all files starting with "read" and ending with ".csv" 
  for find $LOCATION -name $file -type f -mmin -60 do
    if
    sqlldr read*.csv 
then mv "$file" "$HOME/fail/" ;
else{ echo "Failed to load" | mail -s "FAIL" email@email.com}
done
    done

    for file in write*.csv; do
    #run on all files starting with "write" and ending with ".csv" 
      for find $LOCATION -name $file -type f -mmin -60 do
 if
sqlldr write*.csv 
then mv "$filen" "$HOME/unisem/fail/" ;
else { echo "Failed to load 2" | mail -s "FAIL" email@email.com}
done
    done

如果可以按任何顺序处理读...和写...文件,则不需要数组:

shopt -s nullglob
for file in read*.csv; do
    # run on all files starting with "read" and ending with ".csv" 
    sqldr ...
done
for file in write*.csv; do
    # run on all files starting with "write" and ending with ".csv" 
    sqldr ...
done