如何在命令提示符窗口中向 AWS CLI 的输出添加时间戳?

问题描述 投票:0回答:1

我无法将时间戳添加到日志文件中 AWS CLI 的输出

我已经尝试通过 awk 但它给了我错误

aws s3 --output text sync localPath s3://bucketName --endpoint-url https://s3-vpcurl.com | awk '{ print strftime("[%Y-%m-%d %H:%M:%S]"), $0 }' >> C:\syncFromS3\NASToS3-Log.txt

awk: cmd. line:1: { print strftime([%Y-%m-%d
awk: cmd. line:1:                  ^ syntax error

我想打印日志以及日志文件中的时间戳。

例如:-

[2024-04-22 12:20:38] Completed 440 Bytes/949.5 KiB (382 Bytes/s) with 6 file(s) remaining
[2024-04-22 12:20:38] upload: ..\..\syncFromS3\result_90.csv to s3://s3BucketName/IndexFilesCSV/Results/result_90.csv

或者还有其他方法可以做到这一点吗?

任何帮助将不胜感激。

windows amazon-s3 awk cmd aws-cli
1个回答
0
投票

awk 期望

strftime
的格式字符串被引用

尝试

aws s3 --output text sync localPath s3://bucketName --endpoint-url https://s3-vpcurl.com | awk '{ print strftime("[%Y-%m-%d %H:%M:%S]"), $0 }' >> C:\\syncFromS3\\NASToS3-Log.txt

确保重定向在 Windows 上使用双反斜杠作为路径分隔符。

© www.soinside.com 2019 - 2024. All rights reserved.