Below is a Bash script that will query a bucket with the current date specified on the system.
Querying or listing the contents of the S3 bucket is quite a good strategy. Let's say if you need to make sure that important backups are copied or present on S3 bucket.
Or you need to monitor what are the contents being dumped to a specific S3 bucket.
Automating querying S3 contents in Linux using Bash scripting is a good idea. Below is a code that works fine on a Linux system.
#!/bin/bash
varDate=$(date +%Y-%m-%d)
aws s3api list-objects --bucket "name_of-the-bucket" --prefix sub_directory_bucket --query 'Contents[?LastModified>=`'${varDate}'`][].{Key: Key, Size: Size, LastModified: LastModified}' >> /tmp/s3_server_files_$varDate.txt
The script can be configured on a cron task and runs on a daily basis then the date is automatically supplied by the bash script and data is saved on /tmp/ and file will not be overwritten since filename is based on date.
The script assumes that AWS CLI has been downloaded and configured on the Linux server and access keys, password and other settings are working fine.
Cheers...till next time. Stay safe and keep praying that this pandemic will end.
================================
Free Android Apps:
Click links below to find out more:
Excel Keyboard guide:
https://play.google.com/store/apps/details?id=chrisjoms.myexcelapplicationguide
Heaven's Dew Fall Prayer app for Android :
https://play.google.com/store/apps/details?id=soulrefresh.beautiful.prayer
Catholic Rosary Guide for Android:
Pray the Rosary every day, countless blessings will be showered upon your life if you recite the Rosary faithfully.
https://play.google.com/store/apps/details?id=com.myrosaryapp
Divine Mercy Chaplet Guide (A Powerful prayer) BFF = Be Filled Faith:
https://play.google.com/store/apps/details?id=com.dmercyapp
Comments
Post a Comment