My Code and Command line Snippets
AWS
Install AWS CLI
1 |
|
Enable DHCP via userdata on Windows
1 | <powershell> |
List unattached security groups
1 | export AWS_DEFAULT_PROFILE="$AWS_PROFILE" |
List of Instances behind NAT Gateway
1 | export AWS_DEFAULT_OUTPUT="text" |
Fetch S3 Bucket Sizes
1 | aws s3 ls | awk '{print $NF}' | while read line; do |
Check images in launch configuration
1 |
|
List of instances without Environment tag
1 | aws ec2 describe-instances --query 'Reservations[].Instances[?!not_null(Tags[?Key == `Environment`].Value)] | [].[InstanceId]' |
Get Instance metric
1 | aws cloudwatch get-metric-statistics \ |
IAM Role last used
1 | export AWS_DEFAULT_OUTPUT=text |
Check if AMI is being used
1 | awless list images --sort created --reverse --columns id,name,created --format csv | grep years | cut -d, -f1 | while read line; do |
Unused Launch Configurations
1 | aws autoscaling describe-launch-configurations --output text --query 'LaunchConfigurations[].LaunchConfigurationName' | tr -s '\t' '\n' | sort | uniq | grep -v -f <(aws autoscaling describe-auto-scaling-groups --output text --query 'AutoScalingGroups[].LaunchConfigurationName' | tr -s '\t' '\n' | sort | uniq) |
Find orphaned snapshots
1 | aws ec2 describe-snapshots --owner-ids self --output text --query 'Snapshots[].SnapshotId' | tr -s '\t' '\n' | sort | grep -v -f <(aws ec2 describe-images --owners self --output text --query 'Images[].BlockDeviceMappings[].Ebs.SnapshotId' | tr -s '\t' '\n' | sort) |
Change backup and maintenance window of RDS
1 | export RDS_IDENT="$RDS_NAME" |
Delete insufficient CloudWatch alarms
1 | awless list alarms --filter state=insufficient --filter name="<ALARM_PATTERN>" --format csv --columns name,state --no-headers | cut -d, -f1 | while read line; do |
Empty Target Groups
1 | aws elbv2 describe-target-groups --output text --query 'TargetGroups[].TargetGroupArn' | tr -s '\t' '\n' | while read line; do |
List all Regions and AZs
1 | aws ec2 describe-regions | jq -r '.Regions[].RegionName' | while read REGION; do |
Apache HTTP to HTTPS redirection for ELB
1 | <IfModule mod_rewrite.c> |
GCP
List Unused Service Accounts
1 | gcloud recommender insights list \ |
Disabled/Delete Unused Service Accounts
1 | gcloud recommender insights list \ |
Linux
Add admin user in Wordpress using MySQL command line
1 | INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_status`) VALUES ('ccvarun', MD5('ccvarun#123'), 'firstname lastname', 'varun@vrnchndk.in', '0'); |
Generate SSL Cert local using certbot
1 | certbot certonly \ |
Epoch Time to Date
1 | date -d @1560488400 +"%a, %d %b %Y %T %Z" |
Get database sizes in MySQL
1 | SELECT table_schema AS "Database", |
Get database sizes in PostgreSQL
1 | SELECT nspname || '.' || relname AS "relation", |
Last modified files in Linux
1 | find -L "$PATH" -type f -printf "%T@ %Tc %p\n" | sort -n |
Get file path from script
1 | FILE_NAME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/$(basename $0)" |
Create Read Only Ubuntu User
https://gist.github.com/varunchandak/ea71fa2f025248aabc7893279dc12bec
DevOps
Delete build history in jenkins
- open https://<JENKINS_URL>/script
1
2
3
4
5def jobName = "<ENTER_JOB_NAME>"
def job = Jenkins.instance.getItem(jobName)
job.getBuilds().each { it.delete() }
job.nextBuildNumber = 1
job.save()
Random
Cut Youtube Video using ffmpeg
1 | ffmpeg -ss <starting_point> \ |
Decrypt PDF on command line
1 | qpdf --decrypt --password=<PASSWORD> <PDF_PATH> decrypted-<PDF_PATH> |
MacOS trackpad scrolling in vim+iTerm2
1 | defaults write com.googlecode.iterm2 AlternateMouseScroll -bool true |
Split panaroma photos for Instagram uploads
1 | convert "IMG_0853.jpeg" -crop 33%x100% +repage +adjoin "output_%d.jpg" |
- AWS
- Install AWS CLI
- Enable DHCP via userdata on Windows
- List unattached security groups
- List of Instances behind NAT Gateway
- Fetch S3 Bucket Sizes
- Check images in launch configuration
- List of instances without Environment tag
- Get Instance metric
- IAM Role last used
- Check if AMI is being used
- Unused Launch Configurations
- Find orphaned snapshots
- Change backup and maintenance window of RDS
- Delete insufficient CloudWatch alarms
- Empty Target Groups
- List all Regions and AZs
- Apache HTTP to HTTPS redirection for ELB
- GCP
- Linux
- DevOps
- Random