gpt4 book ai didi

bash - aws cli - 在 bash 脚本中下载 rds postgres 日志

转载 作者:行者123 更新时间:2023-12-02 14:03:43 27 4
gpt4 key购买 nike

我编写了一个简单的 bash 脚本来下载我的 RDS postgres 文件。但更重要的是,在终端上一切正常,但是当我在脚本中尝试相同的操作时,我收到错误:

An error occurred (DBLogFileNotFoundFault) when calling the DownloadDBLogFilePortion operation: DBLog File: "error/postgresql.log.2017-11-05-23", is not found on the DB instance

有问题的命令是这样的:

aws rds download-db-log-file-portion --db-instance-identifier foobar --starting-token 0 --output text --log-file error/postgresql.log.2017-11-05-23 >> test.log

一切正常,但是当我在 bash 脚本中放入完全相同的行时,我收到错误消息,没有数据库日志文件 - 这是无意义的,它们就在那里。

这是 bash 脚本:

download_generate_report() {

for filename in $( aws rds describe-db-log-files --db-instance-identifier $1 | awk {'print $2'} | grep $2 )
do

echo $filename
echo $1

aws rds download-db-log-file-portion --db-instance-identifier $1 --starting-token 0 --output text --log-file $filename >> /home/ubuntu/pgbadger_script/postgres_logs/postgres_$1.log.$2
done

}

Tnx,汤姆

最佳答案

我稍微重写了你的脚本,它似乎对我有用。它咆哮着 grep。这使用 jq。

for filename in $( aws rds describe-db-log-files --db-instance-identifier $1 | jq -r '.DescribeDBLogFiles[] | .LogFileName' )
do

aws rds download-db-log-file-portion --db-instance-identifier $1 --output text --no-paginate --log-file $filename >> /tmp/postgres_$1.log.$2
done

关于bash - aws cli - 在 bash 脚本中下载 rds postgres 日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47140873/

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