set Expiry Date S3 AWS cloud front, update with s3cmd - caching

i have uploaded to s3 images for my website and now i want to update the Expiry Date recursively.
i have used the following command:
s3cmd --recursive modify --add-header="Cache-Control:max-age=31536000" s3://ccc-public/
but when i view the image in aws console, it shows Matadata set for Cache Control as specified, but the Expiry Date is still set to None.
i have also tried:
s3cmd --recursive modify --add-header="Expires: Sat, 02 Aug 2016 18:46:39 GMT" --add-header="Cache-Control:max-age=31536000" s3://ccc-public/
and again, this put the metadata for the Expires, but the images still don't have a Expiry Date.
how do i modify all the files so that there is an Expiry Date using s3cmd tool?
any advice much appreciated.

Your command looks correct. Try removing the space after the colon:
--add-header="Expires:Sat, 02 Aug 2016 18:46:39 GMT"
^

Related

How to solve malformed URI while using elasticdump?

I am using Elastcsearch 7.9 and elasticdump 6.7
I am trying to get a dump (.json) file from elastcsearch with all the documents of a index.
I am getting
Thu, 27 May 2021 06:26:35 GMT | starting dump
Thu, 27 May 2021 06:26:35 GMT | Error Emitted => URI malformed
Thu, 27 May 2021 06:26:35 GMT | Error Emitted => URI malformed
Thu, 27 May 2021 06:26:35 GMT | Total Writes: 0
Thu, 27 May 2021 06:26:35 GMT | dump ended with error (get phase) => URIError: URI malformed
My command
elasticdump \
--input=https://username:password#elasticsearchURL:9200/index \
--output=/home/ubuntu/dump.json \
--type=data
Here the problem is password have many special characters.
I cant change the password.
I tried
quotes for password.
Escape special character.
Encoding the url
for all cases I am getting same error
Please help me to send password with special characters(# & % ^ * : ) , $)
Thanks in advance.
actually, ı tried elastisdump but properly not working,you should use elastic snapshot,maybe working in less data but if data is big elasticdump wont work
loook at the elastic snapshot
snapshot
for example using snapshot
PUT /_snapshot/my_fs_backup?pretty
{
"type": "fs",
"settings": {
"location": "/home/zeus/Desktop/denesnapshot",
"compress": true
}
}
#chmod 777 /home/zeus/Desktop/denesnapshot
#create repo
PUT /_snapshot/my_fs_backup/deneme
#get all repo
GET /_snapshot/my_fs_backup/_all
#if you want delete repo
DELETE /_snapshot/my_fs_backup/deneme
#restore
POST /_snapshot/my_fs_backup/deneme/_restore
extra you should add
path.repo: /home/zeus/Desktop/denesnapshot
to elasticsearch.yml file
I imported 1.5 million data and that was 300GB
I made mistake that I have encoded the complete URL.Don't encode the complete URL.
Encode the password while adding password into url.
for example
Password - a#b)c#d%e*f.^gh
Encoded password - a%40b%29c%23d%25e*f.%5Egh
My script will be:
elasticdump \
--input=https://username:a%40b%29c%23d%25e*f.%5Egh#elasticsearchURL:9200/index \
--output=/home/ubuntu/dump.json \
--type=data
Please refer ASCII Encoding Reference for encoding the password

formatting email output in bash

I'm writing a script that sends a user an email when their AWS access keys are too old.
Right now the output looks like this:
Hello tdunphy, \n Your access key: AKIAICDOHVTMEAB6RM5Q was created on Wed Feb 7 22:55:51 EST 2018 and needs to be replaced. All AWS Keys need to be replaced if they are older than 90 days. \n Regards, \n Cloud Ops
I want the message to look like this:
Hello tdunphy,
Your access key: AKIAICDOHVTMEAB6RM5Q was created on Wed Feb 7 22:55:51 EST 2018 and needs to be replaced. All AWS Keys need to be replaced if they are older than 90 days.
Regards,
Cloud Ops
This is the line that sets up the body of the message:
MAIL_TXT1="Hello $user_name, \\n Your access key: $user_access_key1 was created on $date1 and needs to be replaced. All AWS Keys need to be replaced if they are older than 90 days. \\n Regards, \\n Cloud Ops"
Why are the newlines not working in this example? How can I get this to work?
You can use:
template=$'Hello tdunphy, \n Your access key: AKIAICDOHVTMEAB6RM5Q was created on Wed Feb 7 22:55:51 EST 2018 and needs to be replaced. All AWS Keys need to be replaced if they are older than 90 days. \n Regards, \n Cloud Ops'
Then either echo works:
$ echo "$template"
Hello tdunphy,
Your access key: AKIAICDOHVTMEAB6RM5Q was created on Wed Feb 7 22:55:51 EST 2018 and needs to be replaced. All AWS Keys need to be replaced if they are older than 90 days.
Regards,
Cloud Ops
Or printf:
$ printf "%s" "$template"
Your access key: AKIAICDOHVTMEAB6RM5Q was created on Wed Feb 7 22:55:51 EST 2018 and needs to be replaced. All AWS Keys need to be replaced if they are older than 90 days.
Regards,
Cloud Ops
With printf you can assemble the template fields more easily as well:
$ t2=$'Fields:\n\tf1=%s\n\tf2=%s'
$ printf "$t2" 101 102
Fields:
f1=101
f2=102

How to find the date using internet (ie ntp) from bash?

How can I learn date and time from the internet using bash without installing anything extra.
I am basically looking for an equivalent of bash $ date, but using an NTP (or any other way) to get the correct date and time from the internet. All the methods I find (such as ntpd) are meant to correct the system time, which is not my purpose.
date has a lot of options for formatting, but I'm assuming that you just want the date and time:
ntpdate -q time.google.com | sed -n 's/ ntpdate.*//p'
(or any other time server)
If you have ntpd installed & configured then you can use the NTP Query command ntpq -crv which will return;
associd=0 status=04ff leap_none, sync_uhf_radio, 15 events, stale_leapsecond_values,
version="ntpd 4.2.6p5#1.2349-o Mon Feb 6 07:22:46 UTC 2017 (1)",
processor="x86_64", system="Linux/4.10.13-1.el6.elrepo.x86_64", leap=00,
stratum=1, precision=-23, rootdelay=0.000, rootdisp=1.000, refid=PPS,
reftime=dd2c9f10.f25911ee Wed, Aug 2 2017 19:57:20.946,
clock=dd2c9f11.f4251b0a Wed, Aug 2 2017 19:57:21.953, peer=6516, tc=4,
mintc=3, offset=-0.005, frequency=-17.045, sys_jitter=0.110,
clk_jitter=0.007, clk_wander=0.003, tai=37, leapsec=201701010000,
expire=201706010000
You want the line starting clock which gives the time, date etc - you would be best parsing this out with awk or something if you just want the date stamp rather then everything else.
You do not need to be a root user to run the command. It won't set anything, but will query your local server (presuming your running ntp) and present the details.

How to set the correct local time zone in git bash?

I am using git-bash on a Windows system.
The Windows clock shows local time, but inside git-bash everything is in GMT time:
$ date
Mon Mar 31 16:08:57 GMT 2014
Also setting TZ will not change things:
$ TZ="Europe/Berlin" date
Mon Mar 31 16:09:01 GMT 2014
Similarly all times it git log are GMT only.
Is there a way to set the correct timezone in git-bash?
On Windows the TZ variable seems to work differently.
To get the German timezone you have to write:
TZ=GST-1GDT date
If you set it to some "invalid" value like "Europe/Berlin" it will default to GMT.
The same seems to happen on my system when TZ is not set at all.
With the above setting I get Thu Apr 17 16:23:23 GDT 2014 which is not exactly the same as Thu Apr 17 16:23:23 CEST 2014, but at least the time looks right.
Same problem here in my script. Windows was showing 15:47 and the "date" command in gitbash was answering 13:47.
export TZ="CEST-2"
This fixed the problem for me. I wanted Paris time.

How can I format date -u so that the results include timezone offset in a Mac OSX terminal session?

In a terminal session I can use date -u to get
Mon Mar 16 03:34:39 2009 UTC
However, I'd like to include the offset. I'm modifying a TextMate tab trigger so that I can insert the full date including the local offset, in standard UTC format. I believe that would be in the following form:
Mon Mar 16 03:34:39 2009 UTC -0500
So, as you can see, I don't know how to get the timezone offset and combine that with formatted date results.
Try this:
echo `date -u` `date +%z`

Resources