日期:额外的操作数"+%s" [英] date: extra operand '+%s'

查看:1090
本文介绍了日期:额外的操作数"+%s"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个小错误,该错误不会使我的程序每次崩溃,但会使其爬行.它不断给我错误:

I'm running into a slight error that's not crashing my program per say but it brings it to a crawl. It keeps giving me the error:

date: extra operand '+%s'

当我计划删除成千上万个日志文件时,它似乎确实影响了它所能处理的速度.这是有问题的程序:

It seems to really impact the speed of what it can process which is concerning seeing as I plan on deleting hundreds of thousands of log files. Here is the program in question:

#!/bin/bash
# Usage: ./s3DeleteByDate "bucketname" "2m"
aws s3 ls s3://$1 | grep " DIR " -v | while read -r line;
do
 createDate=$(echo "$line" | awk '{print $1" "$2}')
 createDate=`date -d "%Y-%m-%d %H:%M" "$createDate" +%s`
 olderThan=`date -d $2 +%s`
 if [[ $createDate -lt $olderThan ]]
  then
    fileName=`echo $line|awk {'print $4'}`
    if [[ $fileName != "" ]]
      then
        aws s3 rm  s3://$1"$fileName" --exclude "*" --include "*.tmp"
    fi
 fi
done;

推荐答案

我将第7行更改为:date +%s -d"$ createDate".
这是有效的,因为它是一个GNU日期,不允许您指定日期的输入格式.这样可以修复错误.

I changed line 7 to: date +%s -d "$createDate".
This works because it's a GNU date, which doesn't allow you to specify an input format for the date. This fixes the error.

这篇关于日期:额外的操作数"+%s"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆