Skip to content

Instantly share code, notes, and snippets.

Customizing your shell prompt
Shell prompts are extremely customizable. You can customize them in two ways: (1) by using command characters that print out special things and (2) by using colors. Also, customizing the prompt is different in different shells; I'm going to cover tcsh and zsh here. bash is the other popular shell, but I think it sucks, and I never use it, so I'm not going to waste any time on it.
tcsh
zsh
tcsh
I'll start with tcsh, since it's the default BSD and Mac OS X shell. Here's a very simple prompt:
@leandrosiow
leandrosiow / nginx-deployment.yaml
Created April 27, 2021 21:05
Sample Nginx Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: system:aggregated-metrics-reader
labels:
rbac.authorization.k8s.io/aggregate-to-view: "true"
rbac.authorization.k8s.io/aggregate-to-edit: "true"
rbac.authorization.k8s.io/aggregate-to-admin: "true"
rules:
@leandrosiow
leandrosiow / awk-count.sh
Last active April 3, 2020 19:47
Here is how you can quickly count something in a log file
cat /var/log/messages | grep error | awk '{print $1,$2,$3}' | uniq -c | sort -nr | head -n 3
@leandrosiow
leandrosiow / get-instance-types.sh
Last active April 3, 2020 15:54
Get all EC2 Instance Types in All Availability Zones - Reference: https://gist.github.com/trestletech/f93d32e04c601b0584c0ce1a421e9948
#!/bin/bash
echo "Getting list of Availability Zones"
all_regions=$(aws ec2 describe-regions --output text --query 'Regions[*].[RegionName]' | sort)
all_az=()
while read -r region; do
az_per_region=$(aws ec2 describe-availability-zones --region $region --query 'AvailabilityZones[*].[ZoneName]' --output text | sort)
@leandrosiow
leandrosiow / create-ecs-instance.sh
Created April 1, 2020 18:37
Here is how to create an ECS container instance via the CLI
aws ec2 run-instances --image-id ami-088dbc54f17f8a1a2 --count 1 --instance-type t3.large --key-name mysshey --subnet-id subnet-XXXXXXXXXXXXXXXXX --iam-instance-profile Name=ecsInstanceRole --security-group-ids sg-XXXXXXXXXXXXXXXXX --user-data file://ecs.sh
# vi /etc/audit/audit.rules
# Referenced from https://www.thegeekdiary.com/audit-rules-for-monitoring-copy-move-delete-and-kill-commands-in-linux/
#
# Audit Copy, Move, Delete & Create file commands
-a exit,always -F arch=b64 -S execve -F path=/bin/cp -k Copy
-a exit,always -F arch=b64 -S execve -F path=/bin/mv -k Move_Rename
-a exit,always -F arch=b64 -S execve -F path=/bin/rm -k Delete
-a exit,always -F arch=b64 -S execve -F path=/bin/vi -k Create_Edit_View_File
# Audit shutdown & Reboot command
@leandrosiow
leandrosiow / curl_with_info.sh
Last active March 12, 2020 23:16
This script curl a URI and returns useful information such as "Source IP", "Dest IP", "HTTP Version" etc.
while true; do date; curl -so /dev/null -w"\nSource IP:\t\t%{local_ip}:%{local_port}\nDest IP:\t\t%{remote_ip}:%{remote_port}\nHTTP Version:\t\t%{http_version}\nHTTP Status Code:\t%{http_code}\nEffective URL:\t\t%{url_effective}\nRedirect URL:\t\t%{redirect_url}\nNum of Redirects:\t%{num_redirects}\nNum of Connects:\t%{num_connects}\nDownload Size:\t\t%{size_download} bytes\nSSL Verify Result:\t%{ssl_verify_result}\nDNS Resolution Time:\t%{time_namelookup}\nTCP Handshake Time:\t%{time_connect}\nSSL Handshake Time:\t%{time_appconnect}\nPre Transfer Time:\t%{time_pretransfer}\nStart Transfer Time:\t%{time_starttransfer}\nTotal Time Spent:\t%{time_total}\n==========================================\n\n" $1; sleep 5; done
@leandrosiow
leandrosiow / ecs-list-capacityProviderName.sh
Created March 2, 2020 23:10
This script simply displays the capacity provider in a ECS Cluster
#!/bin/bash
CLUSTER=ecs-fargate-spot-only
ECS_SERVICE_NAME=ecs-fargate-hybrid
TASK_ARNS=$(aws ecs list-tasks --cluster $CLUSTER --service-name $ECS_SERVICE_NAME)
TASK_ARNS_STRING=$(echo $TASK_ARNS | jq --raw-output .taskArns[])
# echo $TASK_ARNS_STRING
# aws ecs describe-tasks --cluster ecs-fargate-spot-only --tasks $TASK_ARNS_STRING | grep capacityProviderName
@leandrosiow
leandrosiow / ecs.config
Created February 26, 2020 06:03
Here is a sample of the ECS Agent Configuration (ecs.config)
ECS_CLUSTER=ecs-playground
ECS_ENABLE_CONTAINER_METADATA=true
ECS_RESERVED_MEMORY=256
ECS_ENABLE_TASK_IAM_ROLE=true
ECS_INSTANCE_ATTRIBUTES={"custom_attribute": "value_is_one"}