gpt4 book ai didi

linux - 日期 : extra operand '+%s'

转载 作者:太空宇宙 更新时间:2023-11-04 12:08:28 26 4
gpt4 key购买 nike

我遇到了一个小错误,它并没有让我的程序崩溃,但它让我的程序陷入困境。它一直给我错误:

date: extra operand '+%s'

它似乎真的影响了它可以处理的速度,因为我计划删除数十万个日志文件。这是有问题的程序:

#!/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;

最佳答案

这一行有两个格式说明符:

createDate=`date -d "%Y-%m-%d %H:%M" "$createDate" +%s`

大概您打算使用以下任一方式格式化 $createDate:

createDate=`date -d "$createDate" +"%Y-%m-%d %H:%M"`

或:

createDate=`date -d "$createDate" +%s`

我的钱花在第二个上,因为您稍后会在 if 中使用数值比较。

关于linux - 日期 : extra operand '+%s' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49783993/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com