-1

要求:

  1. 检查当前日期的 /a/b/DROP 和 /a/b/ARCHIVE 目录中是否存在 *.idx 文件的脚本。(完成)

  2. 如果 /a/b/DROP 缺少 *.idx 文件,则从 /a/b/ARCHIVE 复制 *.idx 文件以获取当前日期。(一天只有 1 个文件)

  3. 需要将脚本的输出发送到几个邮件 ID。

    #!/bin/bash
    # Checking DROP ZIP file for current date
    #***************************************
    filestr=`find /a/b/DROP -name "*.idx" -mtime -1 -print`
          if [ "$filestr" = "" ]; then
            echo "DROP ZIP File missing for `date +%D`"
          else
            echo "DROP ZIP file exists for `date +%D`"
          fi
    #Checking ARCHIVE IDX file for current date
    #******************************************
    filestr=`find /a/b/ARCHIVE -name "*.idx" -mtime -1 -print`
      if [ "$filestr" = "" ]; then
        echo "ARCHIVE IDX File missing for `date +%D`"
      else
        echo "ARCHIVE IDX file exists for `date +%D`"
      fi
    

有人可以帮助我实现第二个第三个要求吗?

4

1 回答 1

1
#!/bin/bash
# req.sh
filestr=`find /a/b/DROP -name "*.idx" -mtime -1 -print`
if [ "$filestr" = "" ]; then
  missing="1"
  echo "DROP ZIP File missing for `date +%D`"
else
  echo "DROP ZIP file exists for `date +%D`"
fi
filestr=`find /a/b/ARCHIVE -name "*.idx" -mtime -1 -print`
if [ "$filestr" = "" ]; then
  echo "ARCHIVE IDX File missing for `date +%D`"
elif [ "$missing" = "1" ];then
  echo "Copying from ARCHIVE `date +%D`"
  cp $filestr /a/b/DROP
else
  echo "ARCHIVE IDX file exists for `date +%D`"
fi

运行脚本为

sh req.sh |/usr/sbin/sendmail -r sender@domain.tld recipient1@domain.tld
于 2013-08-02T15:54:45.820 回答