Skip to content

Instantly share code, notes, and snippets.

@Matrix7867
Matrix7867 / s3-get-countries.sh
Created February 13, 2019 08:54
For copying many countries data into S3 bucket with proper format
countri=(SGP IDN)
for i in {8..10}; do
for j in "${countri[@]}"; do
aws s3 cp --recursive s3://<bucket-name>/<directory-name>/year=2019/month=2/day=$i/country=$j ./day=$i/country=$j/
done
done
@Matrix7867
Matrix7867 / cert-delete
Created February 18, 2019 06:36
To Delete Let's Encrypt SSL cert for a domain
certbot delete --cert-name <domain.io>
@Matrix7867
Matrix7867 / delete-all-awslambda-function.sh
Created May 10, 2019 07:58
To delete all AWS lambda function from your account
aws lambda list-functions | grep FunctionName | cut -d':' -f 2 | sed 's/"//g' | sed 's/,//g' | while read -r line; do aws lambda delete-function --function-name $line; done;
@Matrix7867
Matrix7867 / gzip-json.sh
Created June 12, 2019 10:46
Gzipping all *.json file to gzip
for i in *.json; do gzip $i; done;
@Matrix7867
Matrix7867 / copy-json-to-s3.sh
Created June 12, 2019 14:44
Copy any custom file to S3 via looping it
for i in *.json; do aws s3 cp $i s3://s3bucket/ls/ls/ ; done;
@Matrix7867
Matrix7867 / rename000.sh
Created July 18, 2019 10:43
rename any files with three digit 000 increment
#!/bin/bash
count=001
newname=segmentmembership
for i in *.json.gz;
do
c=`printf '%0.3d\n' $count`
mv $i $newname.$c.json.gz
count=$((count+001))
@Matrix7867
Matrix7867 / createmd5sum.sh
Last active August 6, 2019 09:51
create md5sum files for json.gz files
for i in *.gz; do md5sum $i > /home/ubuntu/lot/$i.md5; done;
@Matrix7867
Matrix7867 / docker-rm-stop
Last active July 30, 2019 10:40
remove all stopped/exited containers
sudo docker ps -a | grep "Exited" | sudo xargs docker rm
@Matrix7867
Matrix7867 / uploading-app-logs-to-s3
Created September 13, 2019 07:45
bash script to upload on S3
#!/bin/bash
logdirect="/dataa/app-service-1.0-SNAPSHOT/"
cd $logdirect
ls | grep ".log.gz" | awk '{print $1}' | head -n -3 | xargs -I {} aws s3 mv {} s3://cass-doc/app-logs/
@Matrix7867
Matrix7867 / metadata-gcp-instance-hostname
Created February 5, 2020 06:47
Getting hostname from GCP instance via curl into metadata
#Getting hostname of the instance via Metadata
curl http://metadata.google.internal/computeMetadata/v1/instance/hostname -H "Metadata-Flavor: Google"
#Getting ID of the instance
curl http://metadata.google.internal/computeMetadata/v1/instance/id -H "Metadata-Flavor: Google"
#Getting Instance-name via Metadata
curl http://metadata.google.internal/computeMetadata/v1/instance/name -H "Metadata-Flavor: Google"