Hari Sekhon - DevOps Bash Tools
LineCount Cocomo
Codefresh
Semaphore
Azure DevOps Pipeline
1200+ DevOps Shell Scripts and Advanced Bash environment.
Fast, Advanced Systems Engineering, Automation, APIs, shorter CLIs, etc.
Heavily used in many GitHub repos, dozens of DockerHub builds (Dockerfiles) and 600+ CI builds.
Summary
- Scripts for many popular DevOps technologies, see Index below for more details
- Advanced configs for common tools like Git, vim, screen, tmux, PostgreSQL psql etc...
- CI configs for most major Continuous Integration products (see CI builds page)
- CI scripts for a drop-in framework of standard checks to run in all CI builds, CI detection, accounting for installation differences across CI environments, root vs user, virtualenvs etc.
- API scripts auto-handling authentication, tokens and other details to quickly query popular APIs with a few keystrokes just supplying the
/path/endpoint - Advanced Bash environment -
.bashrc+.bash.d/*.sh- aliases, functions, colouring, dynamic Git & shell behaviour enhancements, automatic pathing for installations and major languages like Python, Perl, Ruby, NodeJS, Golang across Linux distributions and Mac. See .bash.d/README.md - Installs the best systems packages - AWS CLI, Azure CLI, GCloud SDK, Digital Ocean CLI, Terraform, Terragrunt, GitHub CLI, Kubernetes kubectl & kustomize, Helm, eksctl, Docker-Compose, jq and many others... extensive package lists for servers and desktops for most major Linux distributions package managers and Mac
install/- contains many installation scripts for popular open source software and direct binary downloads from GitHub releasesconfigs/- contains many dot configs for common technologies like ViM, top, Screen, Tmux, MySQL, PostgreSQL etc.setup/- contains setup scripts, package lists, extra configs, Mac OS X settings etc.- Utility Libraries used by many hundreds of scripts and builds across repos:
.bash.d/- interactive librarylib/- scripting and CI library- SQL Scripts - 100+ scripts for PostgreSQL, MySQL, AWS Athena + CloudTrail, Google BigQuery
- Templates - templates for common programming languages and build configs
- Kubernetes Configs - Kubernetes YAML configs for most common scenarios, including Production Best Practices, Tips & Tricks
See Also: similar DevOps repos in other languages
Hari Sekhon
Cloud & Big Data Contractor, United Kingdom
(ex-Cloudera, former Hortonworks Consultant)
(you're welcome to connect with me on LinkedIn)
Quick Setup
To bootstrap, install packages and link in to your shell profile to inherit all configs, do:
curl -L https://git.io/bash-bootstrap | sh
- Adds sourcing to
.bashrc/.bash_profileto automatically inherit all.bash.d/*.shenvironment enhancements for all technologies (see Inventory below) - Symlinks
.*config dotfiles to$HOMEfor git, vim, top, htop, screen, tmux, editorconfig, Ansible, PostgreSQL.psqlrcetc. (only when they don't already exist so there is no conflict with your own configs) - Installs OS package dependencies for all scripts (detects the OS and installs the right RPMs, Debs, Apk or Mac HomeBrew packages)
- Installs Python packages
- Installs AWS CLI
To only install package dependencies to run scripts, simply cd to the git clone directory and run make:
git clone https://github.com/HariSekhon/DevOps-Bash-tools bash-tools
cd bash-tools
make
make install sets your shell profile to source this repo. See Individual Setup Parts below for more install/uninstall options.
Index
- Dot Configs -
.gitconfig,.vimrc,.screenrc,.tmux.conf,.toprc,.gitignore... - Bash Environment & Libraries -
.bashrc,.bash.d/interactive library,lib/scripting library - Installation Scripts for many popular open source technologies
- Linux & Mac - curl OAuth / JWT, LDAP, find duplicate files, SSL certificate get/validate, URL encoding/decoding, Vagrant
- Mac & AppleScript - Mac settings and UI automation scripts, send keystrokes, mouse clicks, detect foreground app, switch app, detect locked screen or screensaver, activate screensaver, Hammerspoon system event handlers such as automatically switching audio to be able to Shazam while watching on AirPods
- Monitoring - Grafana, Prometheus, Node Exporter, scripted collection of common Linux & Mac cli monitoring stats and log locations for quick generation of vendor support tarball bundles both locally and over SSH
- AWS - Amazon Web Services - AWS account summary, lots of IAM reports, CIS Benchmark config hardening, EC2, ECR, EKS, Spot termination, S3 access logging, KMS key rotation info, SSM, CloudTrail, CloudWatch billing alarm with SNS notification topic and subscription for email alerts
- GCP - Google Cloud Platform - massive GCP auto-inventory, scripts for GCE, GKE, GCR, Secret Manager, BigQuery, Cloud SQL, Cloud Scheduler, Terraform service account creation
- Kubernetes - massive Kubernetes auto-inventory, cluster management scripts & tricks
- Docker - Docker API, Dockerhub API, Quay.io API scripts
- Databases - fast CLI wrappers, instant Docker sandboxes (PostgreSQL, MySQL, MariaDB, SQLite), SQL scripts, SQL script testers against all versions of a DB, advanced
.psqlrc - Data - data tools, converters and format validators for Avro, Parquet, CSV, JSON, INI / Properties files (Java), LDAP LDIF, XML, YAML
- Big Data & NoSQL - Kafka, Hadoop, HDFS, Hive, Impala, ZooKeeper, Cloudera Manager API & Cloudera Navigator API scripts
- Git - GitHub, GitLab, Bitbucket, Azure DevOps - scripts for Git local & mirror management, GitHub, GitLab & BitBucket APIs
- Markdown - generate Markdown indexes and debug
mdlissues like MD005 inconsistent list indentation in largeREADME.mdfiles - CI/CD - Continuous Integration / Continuous Delivery - API scripts & build pipeline configs for most major CI systems:
- Jenkins, Concourse, GoCD, TeamCity - one-touch boot & build
- Azure DevOps Pipelines, GitHub Actions Workflows, GitLab CI, BitBucket Pipelines, AppVeyor, BuildKite, Travis CI, Circle CI, Codefresh, CodeShip, Drone.io, Semaphore CI, Shippable ...
- Terraform Cloud, Octopus Deploy
- Checkov / Bridgecrew Cloud
- AI & IPaaS - OpenAI (ChatGPT), Make.com
- Internet Services - Google Maps, Cloudflare, DataDog, Digital Ocean, Kong API Gateway, GitGuardian, Jira, NGrok, Traefik, Pingdom, Wordpress and various pastebins and file upload sites
- Java - Java utilies to debug running Java programs or decompile Java JAR code for deeper debugging
- Python - Python utilities & library management
- Perl - Perl utilities & library management
- Golang - Golang utilities
- Diagrams - scripts to generate diagrams from D2lang, MermaidJS and Python Mingrammer source code used in my HariSekhon/Diagrams-as-Code repo
- Media - video downloaders & converts, MP3 metadata editing, grouping and ordering of albums and audiobooks, mkv/avi to mp4 converters, 720p video downscaler for posting to social media, download YouTube videos or even entire channels and videos from other social media sites like Twitter / X or Facebook, terminal gif capture
- Spotify - 40+ Spotify API scripts for backups, managing playlists, track deduplication, URI conversion, search, add/delete, liked tracks, followed artists, top artists, top tracks etc.
- More Linux & Mac - more systems administration scripts, package installation automation
- Builds, Languages & Linting - programming language, build system & CI linting
- Templates - Templates for AWS, GCP, Terraform, Docker, Jenkins, Cloud Build, Vagrant, Puppet, Python, Bash, Go, Perl, Java, Scala, Groovy, Maven, SBT, Gradle, Make, GitHub Actions, CircleCI, Jenkinsfile, Makefile, Dockerfile, docker-compose.yml etc.
- Kubernetes Configs - Kubernetes YAML configs for most common scenarios, including Production Best Practices, Tips & Tricks
Dot Configs
Top-level dotfiles and configs/ directory:
.*- dot conf files for lots of common software eg. advanced.vimrc,.gitconfig, massive.gitignore,.editorconfig,.screenrc,.tmux.confetc..vimrc- contains many awesome vim tweaks, plus hotkeys for linting lots of different file types in place, including Python, Perl, Bash / Shell, Dockerfiles, JSON, YAML, XML, CSV, INI / Properties files, LDAP LDIF etc without leaving the editor!.screenrc- fancy screen configuration including advanced colour bar, large history, hotkey reloading, auto-blanking etc..tmux.conf- fancy tmux configuration include advanced colour bar and plugins, settings, hotkey reloading etc.- Git:
.gitconfig- advanced Git configuration.gitignore- extensive Git ignore of trivial files you shouldn't commit- enhanced Git diffs
- protections against committing AWS secret keys or merge conflict unresolved files
Bash Environment & Libraries
Top-level .bashrc and .bash.d/ directory:
.bashrc- shell tuning and sourcing of.bash.d/*.sh.bash.d/*.sh- thousands of lines of advanced bashrc code, aliases, functions and environment variables for:- Linux & Mac
- SCM - Git, Mercurial, Svn
- AWS
- GCP
- Docker
- Kubernetes
- Kafka
- Vagrant
- automatic GPG and SSH agent handling for handling encrypted private keys without re-entering passwords, and lazy evaluation to only prompt key load the first time SSH is called
- and lots more - see .bash.d/README for a more detailed list
- run
make bashto link.bashrc/.bash_profileand the.*dot config files to your$HOMEdirectory to auto-inherit everything lib/*.sh- Bash utility libraries full of functions for Docker, environment, CI detection (Travis CI, Jenkins etc), port and HTTP url availability content checks etc. Sourced from all my other GitHub repos to make setting up Dockerized tests easier.
Installation Scripts
install/install_*.sh- various simple to use installation scripts for common technologies like:- AWS CLI
- Azure CLI
- GCloud SDK
- GitHub CLI
- Terraform
- Terragrunt
- Direnv
- Ansible
- K3s
- MiniKube (Kubernetes)
- MiniShift (Redhat OpenShift / OKD dev VMs)
- Maven
- Gradle
- SBT
- EPEL
- RPMforge
- Homebrew
- Travis CI
- Circle CI
- AppVeyor
- BuildKite
- Avro Tools
- Parquet Tools
- Prometheus
- various JDKs and RDBMS JDBC connector jars
- and many more...
Linux & Mac
bin/ directory:
login.sh- logs to major Cloud platforms if their credentials are found in the environment, CLIs such as AWS, GCP, Azure, GitHub... Docker registries: DockerHub, GHCR, ECR, GCR, GAR, ACR, Gitlab, Quay...clean_caches.sh- cleans out OS package and programming language caches - useful to save space or reduce Docker image sizecommand_return_to_current_window.sh- runs a Mac or Linux command that opens a window and then switches back to the original foreground windowcrypto_dice_rolls.sh- generates 100 random dice rolls to test a new crypto hardware wallet's fidelity (do not use this for your real crypto seed as your machine could be infected with malware which steals your seed phrase)delete_duplicate_files.sh- deletes duplicate files with (N) suffixes, commonly caused by web browser downloads, in the given or current directory. Checks they're exact duplicates of a matching basename file without the (N) suffix with the exact same checksum for safety. Prompts to delete per file. To auto-accept deletions, doyes | delete_duplicate_files.sh. This is a fast way of cleaning up your~/Downloadsdirectory and can be put your user crontabdisk_speed_read_sequential_dd.sh- runs a sequential read speed test from the given file using dd and bypassing filesystem cache for a more accurate testdisk_speed_read_random_dd.sh- runs a random I/O read speed test from the given file using dd and bypassing filesystem cache for a more accurate testdisk_speed_write_sequential_dd.sh- runs a sequential write speed test to a file in the given or current directory using dd and bypassing filesystem cache for a more accurate testdisk_speed_read_sequential_fio.sh- runs a sequential read speed test in the current or given directory using fiodisk_speed_read_random_fio.sh- runs a random I/O read test in the current or given directory using fiodisk_speed_write_sequential_fio.sh- runs a sequential write speed test to the current or given directory using fiodisk_speed_write_random_fio.sh- runs a sequential write speed test to the current or given directory using fiodownload_url_file.sh- downloads a file from a URL using wget with no clobber and continue support, or curl with atomic replacement to avoid race conditions. Used bygithub/github_download_release_file.sh,github_download_release_jar.sh, andinstall/download_*_jar.shcurl_auth.sh- shortenscurlcommand by auto-loading your OAuth2 / JWT API token or username & password from environment variables or interactive starred password prompt through a ram file descriptor to avoid placing them on the command line (which would expose your credentials in the process list or OS audit log files). Used by many other adjacent API querying scriptscurl_with_cookies.sh- extracts cookies for a given URL from your\$BROWSER's cookie jar and passes them to thecurlcommand along with the rest of the args (workaround for older curl builds and Homebrew builds that don't have the newer `--cookies-from-browser functionality)find_duplicate_files*.sh- finds duplicate files by size and/or checksum in given directory trees. Checksums are only done on files that already have matching byte counts for efficiencyfind_broken_links.sh- find broken links with delays to avoid tripping defensesfind_broken_symlinks.sh- find broken symlinks pointing to non-existent files/directoriesfind_lock.sh- tries to find if a lockfile is used in the given or current working directory by taking snapshots of the file list before and after a prompt in which you should open/close an applicationforeach_path_bin.sh- runs each binary of the given name found in$PATHwith the args given. Useful to find all the installed versions of a program in different paths eg.~/bin/vs/usr/local/bin/eg.foreach_path_bin.sh terraform --versionhttp_duplicate_urls.sh- find duplicate URLs in a given web pagehtmldecode.sh- decodes HTML encoding. Detects available tools such as Perl, Python or xmlstarlet and uses whatever is availableldapsearch.sh- shortensldapsearchcommand by inferring switches from environment variablesldap_user_recurse.sh/ldap_group_recurse.sh- recurse Active Directory LDAP users upwards to find all parent groups, or groups downwards to find all nested users (useful for debugging LDAP integration and group-based permissions)linux_distro_versions.sh- quickly returns the list of major versions for a given Linux distrolinux_command_return_to_current_window.sh- runs a Linux command that opens a window and then switches back to the original foreground windowmac_command_return_to_current_window.sh- runs a Mac command that opens a window and then switches back to the original foreground windowdiff_line_threshold.sh- compares two files vs a line count diff threshold to determine if they are radically different. Used to avoid overwriting files which are not mere updates but completely different filesmv.sh- moves directory trees resumably and removes the source files as they're copied over. Useful to migrate data from one disk to another, optionally with checksums. Uses rsync and shows the overall % of files transferred and the MB/s data transfer ratenetwork_gateway.sh- get the network gateway IP address on Linux or Macnetwork_randomize_mac_address.sh- assigns a new random mac address to your network interfaceopen.sh- opens given arg, file or URL using whatever default system opener is available for Linux or Macorganize_downloads.sh- moves files of well-known extensions in the$HOME/Downloadsdirectory older than 1 week to capitalized subdirectories of their type to keep the$HOME/Downloads/directory tidycopy_to_clipboard.sh- copies stdin or string arg to system clipboard on Linux or Macpaste_from_clipboard.sh- pastes from system clipboard to stdout on Linux or Macpaste_from_clipboard_upon_changes.sh- pastes from system clipboard to stdout on Linux or Mac whenever the clipboard changespaste_diff_settings.sh- takes snapshots of before and after clipboard changes and diffs them to show config changesprocesses_ram_sum.sh- sums the RAM usage of all processes matching a given regex in GB to one decimal placepldd.sh- parses/procon Linux to show the runtime.soloaded dynamic shared libraries a program pid is using. Runtime equivalent of the classic staticlddcommand and because the systemplddcommand often fails to attach to a processrandom_select.sh- selects one of given args at random. Useful for sampling, running randomized subsets of large test suites etc.random_number.sh- prints a random integer between two integer arguments (inclusive)random_string.sh- prints a random alphanumeric string of a given lengthscreen_terminal_to_stdout.sh- dumps the GNU Screen terminal output to stdoutscreen_terminal_to_clipboard.sh- dumps the GNU Screen terminal output to a temp file and copies to clipboard for sharing & debugging purposesshields_embed_logo.sh- base64 encodes a given icon file or url and prints thelogo=...url parameter you need to add the shields.io badge urlshorten_text_selection.sh- shortens the selected text in the prior window. Replacesandwith&and crushes out multiple blank lines. I use this for LinkedIn comments due to the short 1250 character limitshred_file.sh- overwrites a file 7 times to DoD standards before deleting it to prevent recovery of sensitive informationshred_free_space.sh- overwrites free space to prevent recovery of sensitive information for files that have already been deletedsplit.sh- split large files into N parts (defaults to the number of your CPU cores) to parallelize operations on themssl_get_cert.sh- gets a remotehost:portserver's SSL cert in a format you can pipe, save and use locally, for example in Java truststoresssl_verify_cert.sh- verifies a remote SSL certificate (battle tested more feature-rich versioncheck_ssl_cert.plexists in the Advanced Nagios Plugins repo)ssl_verify_cert_by_ip.sh- verifies SSL certificates on specific IP addresses, useful to test SSL source addresses for CDNs, such as Cloudflare Proxied sources before enabling SSL Full-Strict Mode for end-to-end, or Kubernetes ingresses (see alsocurl_k8s_ingress.sh)text_filter_ending_substrings.sh- for a given patterns file of substring endings, print all lines that match in the following files. Uses awk to safely handle all characters as literals, unlike grep, while also maintaining end anchoring which you cannot do usinggrep -F. Optimized awk code uses a bucketing hash for performance to not attempt matching lines which are shorter than patterns, reducing the number of match attemptstmux_vertical.sh- launches tmux with N-way vertical shell split or commands given as args in equally balanced vertical panes. Fast way to launch a bunch of shell or commands in an easily reviewable side-by-side waytmux_horizontal.sh- same as above but split horizontallytmux_square.sh- same as above but with 4 panes in a square tiled viewurlencode.sh/urldecode.sh- URL encode/decode quickly on the command line, in pipes etc.urlextract.sh- extracts the URLs from a given string arg, file or standard inputurl_extract_redirects.sh- extracts the URLs from a given string arg, file or standard input, queries each one and outputs the redirected urls instead to stdouturl_replace_redirects.sh- extracts the URLs from a given string arg, file or standard input, queries each one and outputs the entire contents to stdout with the urls replaced by the redirected urlsurlopen.sh- opens the URL given as an arg, or first URL found from stdin or a given file. Uses the system's default browservagrant_hosts.sh- generate/etc/hostsoutput from aVagrantfilevagrant_total_mb.sh- calculate the RAM committed to VMs in aVagrantfile
See also Knowledge Base notes for Linux and Mac.
Mac & AppleScript
Mac automation scripts to automate the Mac UI and settings
bin/ directory:
mac_diff_settings.sh- takes before and after snapshots of UI setting changes and diffs them to make it easy to finddefaultskeys to add tosetup/mac_settings.shto save settingsmac_restore_file.sh- checks all the backup mount points for the latest backup that has a given file and then restores itmac_backup_du_in_progress.sh- find large files in the currently in-progress Time Machine backup to find out what is taking so long and racking up so many more GB of changes than you expect. This helps discover large but unnecessary files that you might want to exclude using the adjacent scriptmac_backup_exclude_paths.shmac_backup_exclude_paths.sh- excludes many common large caches, docker and VM paths from macOS Time Machine backupsmac_backup_find_excluded_paths.sh- does a deep search for macOS Time Machine excluded backup paths on file/folder attributes. See HariSekhon/Knowledge-Base Mac page for whymac_command_return_to_current_window.sh- runs a Mac command that opens a window and then switches back to the original foreground windowmac_rmdir.sh- safely delete a directory on Mac only if it is empty of actual data, by first removing macOS hidden metadata files and dirs such as.fseventsd/,.Spotlight-V100/and.DS_Store- straightrmdirfails otherwisemac_iso_to_usb.sh- converts a given ISO file to a USB bootable image and burns it onto a given or detected inserted USB drivemac_ramdisk.sh- creates a mac ramdisk of given MB size. Useful for performance, or even testing disk write scripts such asdisk_speed_write_*.shwithout wearing out your SSDmac_delete_local_snapshots.sh- deletes local macOS snapshots to free up disk space. When there is a substantial discrepancy between what thedf -hcommand and the Finder UI shows, this is often the causecopy_to_clipboard.sh- copies stdin or string arg to system clipboard on Linux or Macpaste_from_clipboard.sh- pastes from system clipboard to stdout on Linux or Macpaste_from_clipboard_upon_changes.sh- pastes from system clipboard to stdout on Linux or Mac whenever the clipboard changespaste_diff_settings.sh- Takes snapshots of before and after clipboard changes and diffs them to show config changes
applescript/ directory:
keystrokes.sh- send N keystroke combinationsmouse_clicks.sh- send N mouse click combinations to sequence of screen coordinatesget_mouse_coordinates.sh- print the current mouse coordinates - to know what to pass to above scriptmouse_clicks_remote_desktop.sh- switches to Microsoft Remote Desktop, waits 10 seconds and then clicks the mouse once a minute to prevent the screensaver from coming on. Workaround to Active Directory Group Policies that don't let you disable the screensaver. Point your mouse to an area that will have no mouse click effect, the Cmd-Tab to Terminal and run thisget_frontmost_process_title.scpt- detect the frontmost window- to detect if you should send keystrokes / mouse clicks)
set_frontmost_process.scpt- switch to bring the given app to the foreground to send keystrokes / mouse clicks to itbrowser_get_default.scpt- get the default configured browser in format passable to Applescript (for above script)is_screen_locked.py- detect if the screen is locked to stop sending keystrokes or mouse clicksis_screensaver_running.scpt- detect if the screensaver is running to stop sending keystrokes or mouse clicksreopen_app.sh- relaunch a given app (used to reload Shazam to detect DB changes after removing tracks programmatically from its DB)spotify_app_search.sh- runs a search in the Spotify App on Mac using Applescriptspotify_app_search_filelist.sh- searches the Spotify App for each track in a file, prompting to continue to the next trackshazam_app_dump_tracks.sh- dumpsartist - trackone per line from the Shazam local sqlite DBshazam_app_delete_track.sh- deletes a given"artist" "track"from the Shazam local sqlite DBshazam_search_spotify_then_delete_track.sh- searches for each Shazam'd track in the local Spotify desktop app, then prompts to delete each track from the local Shazam DB once you've saved it in Spotify. Useful to migrate Shazam'd tracks to Spotify after Apple removed the integrationscreensaver_activate.scpt- activate screensavershorten_text_selection.scpt- shortens the selected text in the prior window. Replacesandwith&and crushes out multiple blank lines. I use this for LinkedIn comments due to the short 1250 character limitstart_app_at_login.sh- adds an app to the Login items to auto-start
Hammerspoon code has been moved to its own repo:
Readme Card
See also Mac page in HariSekhon/Knowledge-Base.
Monitoring
monitoring/ directory:
dump_stats.sh- dumps common command outputs to text files in a local tarball. Useful to collect support information for vendor support casesgrafana_api.sh- queries the Grafana API with authenticationlog_timestamp_large_intervals.sh- finds log lines whose timestamp intervals exceed the given number of seconds and outputs those log lines with the difference between the last and current timestamps. Useful to find actions that are taking a long time from log files such as CI/CD logsprometheus.sh- starts Prometheus locally, downloading it if not found in$PATHprometheus_docker.sh- starts Prometheus in Docker usingdocker-composeprometheus_node_exporter.sh- starts Prometheusnode_exporterlocally, downloading it if not found in$PATHssh_dump_stats.sh- uses SSH anddump_stats.shto dump common command outputs from remote servers to a local tarball. Useful for vendor support casesssh_dump_logs.sh- Uses SSH to dump logs from server to local text files for uploading to vendor support cases
See doc pages in HariSekhon/Knowledge-Base on Grafana, Prometheus, OpenTSDB, InfluxDB etc.
Databases
mysql/, postgres/, sql/ and bin/ directories:
- sql/ - 100+ SQL scripts for PostgreSQL, MySQL, Google BigQuery and AWS Athena CloudTrail logs integration
sqlite.sh- one-touch SQLite, starts sqlite3 shell with sample 'chinook' database loadedmysql*.sh- MySQL scripts:mysql.sh- shortensmysqlcommand to connect to MySQL by auto-populating switches from both standard environment variables like$MYSQL_TCP_PORT,$DBI_USER,$MYSQL_PWD(see doc) and other common environment variables like$MYSQL_HOST/$HOST,$MYSQL_USER/$USER,$MYSQL_PASSWORD/$PASSWORD,$MYSQL_DATABASE/$DATABASEmysql_foreach_table.sh- executes a SQL query against every table, replacing{db}and{table}in each iteration eg.select count(*) from {table}mysql_*.sh- various scripts usingmysql.shfor row counts, iterating each table, or outputting clean lists of databases and tables for quick scriptingmysqld.sh- one-touch MySQL, boots docker container + drops in tomysqlshell, with/sqlscripts mounted in container for easy sourcing eg.source /sql/<name>.sql. Optionally loads sample 'chinook' database- see also the SQL Scripts repo for many more straight MySQL SQL scripts
mariadb.sh- one-touch MariaDB, boots docker container + drops in tomysqlshell, with/sqlscripts mounted in container for easy sourcing eg.source /sql/<name>.sql. Optionally loads sample 'chinook' databasepostgres*.sh/psql.sh- PostgreSQL scripts:postgres.sh- one-touch PostgreSQL, boots docker container + drops in topsqlshell, with/sqlscripts mounted in container for easy sourcing eg.\i /sql/<name>.sql. Optionally loads sample 'chinook' databasepsql.sh- shortenspsqlcommand to connect to PostreSQL by auto-populating switches from environment variables, using both standard postgres supported environment variables like$PG*(see doc) as well as other common environment variables like$POSTGRESQL_HOST/$POSTGRES_HOST/$HOST,$POSTGRESQL_USER/$POSTGRES_USER/$USER,$POSTGRESQL_PASSWORD/$POSTGRES_PASSWORD/$PASSWORD,$POSTGRESQL_DATABASE/$POSTGRES_DATABASE/$DATABASEpostgres_foreach_table.sh- executes a SQL query against every table, replacing{db},{schema}and{table}in each iteration eg.select count(*) from {table}postgres_*.sh- various scripts usingpsql.shfor row counts, iterating each table, or outputting clean lists of databases, schemas and tables for quick scriptingchecks/check_sqlfluff.sh- recursively iterates all SQL code files found in the given or current directory and runs SQLFluff linter against them, inferring the different SQL dialects from each path/filename/extension
AWS - Amazon Web Services
aws/ directory:
- AWS scripts -
aws_*.sh: aws_profile.sh- switches to an AWS Profile selected from a convenient interactive menu list of AWS profiles from$AWS_CONFIG_FILE- useful when you have lots of AWS work profiles- see also HariSekhon/Environments for automated switching using direnv when
cding into relevant directories
- see also HariSekhon/Environments for automated switching using direnv when
aws_cli_create_credential.sh- creates an AWS service account user for CI/CD or CLI with Admin permissions (or other group or policy), creates an AWS Access Key, saves a credentials CSV and even prints the shell export commands and aws credentials file config to configure your environment to start using it. Useful trick to avoid CLI reauth toaws sso loginevery day.aws_terraform_create_credential.sh- creates a AWS terraform service account with Administrator permissions for Terraform Cloud or other CI/CD systems to run Terraform plan and apply, since no CI/CD systems can work with AWS SSO workflows. Stores the access key as both CSV and prints shell export commands and credentials file config as above.envrc-aws- copy to.envrcfor direnv to auto-load AWS configuration settings such as AWS Profile, Compute Region, EKS cluster kubectl context etc.- calls
.envrc-kubernetesto set thekubectlcontext isolated to current shell to prevent race conditions between shells and scripts caused by otherwise naively changing the global~/.kube/configcontext
- calls
aws_sso_ssh.sh- launches local AWS SSO authentication pop-up (if not already authenticated), then scp's the latest resultant~/.aws/sso/cache/file to the remote server and SSH's there so that you can use AWS CLI or kubectl to EKS remotely on that server easily, without having to copy and paste the token from remote aws sso login to your local web browseraws_terraform_create_s3_bucket.sh- creates a Terraform S3 bucket for storing the backend state, locks out public access, enables versioning, encryption, and locks out Power Users role and optionally any given user/group/role ARNs via a bucket policy for safetyaws_terraform_create_dynamodb_table.sh- creates a Terraform locking table in DynamoDB for use with the S3 backend, plus custom IAM policy which can be applied to less privileged accountsaws_terraform_create_all.sh- runs all of the above, plus also applies the custom DynamoDB IAM policy to the user to ensure if the account is less privileged it can still get the Terraform lock (useful for GitHub Actions environment secret for a read only user to generate Terraform Plans in Pull Request without needing approval)aws_terraform_iam_grant_s3_dynamodb.sh- creates IAM policies to access any S3 buckets and DynamoDB tables withterraform-stateortf-statein their names, and attaches them to the given user. Useful for limited permissions CI/CD accounts that run Terraform Plan eg. in GitHub Actions pull requestsaws_account_summary.sh- prints AWS account summary inkey = valuepairs for easy viewing / grepping of things likeAccountMFAEnabled,AccountAccessKeysPresent, useful for checking whether the root account has MFA enabled and no access keys, comparing number of users vs number of MFA devices etc. (see alsocheck_aws_root_account.pyin Advanced Nagios Plugins)aws_billing_alarm.sh- creates a CloudWatch billing alarm and SNS topic with subscription to email you when you incur charges above a given threshold. This is often the first thing you want to do on an accountaws_budget_alarm.sh- creates an AWS Budgets billing alarm and SNS topic with subscription to email you when both when you start incurring forecasted charges of over 80% of your budget, and 90% actual usage. This is often the first thing you want to do on an accountaws_batch_stale_jobs.sh- lists AWS Batch jobs that are older than N hours in a given queueaws_batch_kill_stale_jobs.sh- finds and kills AWS Batch jobs that are older than N hours in a given queueaws_cloudfront_distribution_for_origin.sh- returns the AWS CloudFront ARN of the distribution which serves origins containing a given substring. Useful for quickly finding the CloudFront ARN needed to give permissions to a private S3 bucket exposed via CloudFrontaws_cloudtrails_cloudwatch.sh- lists Cloud Trails and their last delivery to CloudWatch Logs (should be recent)aws_cloudtrails_event_selectors.sh- lists Cloud Trails and their event selectors to check each one has at least one event selectoraws_cloudtrails_s3_accesslogging.sh- lists Cloud Trails buckets and their Access Logging prefix and target bucket. Checks S3 access logging is enabledaws_cloudtrails_s3_kms.sh- lists Cloud Trails and whether their S3 buckets are KMS securedaws_cloudtrails_status.sh- lists Cloud Trails status - if logging, multi-region and log file validation enabledaws_config_all_types.sh- lists AWS Config recorders, checking all resource types are supported (should be true) and includes global resources (should be true)aws_config_recording.sh- lists AWS Config recorders, their recording status (should be true) and their last status (should be success)aws_csv_creds.sh- prints AWS credentials from a CSV file as shell export statements. Useful to quickly switch your shell to some exported credentials from a service account for testing permissions or pipe to upload to a CI/CD system via an API (eg.jenkins_cred_add*.sh,github_actions_repo*_set_secret.sh,gitlab_*_set_env_vars.sh,circleci_*_set_env_vars.sh,bitbucket_*_set_env_vars.sh,terraform_cloud_*_set_vars.sh,kubectl_kv_to_secret.sh). Supports new user and new access key csv file formats.aws_codecommit_csv_creds.sh- prints AWS CodeCommit Git credentials from a CSV file as shell export statements. Similar use case and chaining as aboveaws_ec2_*.sh- AWS EC2 scripts:aws_ec2_instance_*.sh- AWS EC2 Instance scripts:aws_ec2_instance_name_to_id.sh- looks up an EC2 instance ID from an instance name with extra safety checks that only a single instance ID is returned and a reverse lookup on that instance ID to re-verify it matches the name. This level of safety is important when wanting to terminate an EC2 instance by name. If an instance ID is passed, returns it as is for convenience. Used by adjacent scriptsaws_ec2_instances.sh- lists AWS EC2 instances, their DNS names and States in an easy to read table outputaws_ec2_instance_ip.sh- determines an EC2 instance IP address, trying first for a public IP, or failing that a private IPaws_ec2_instance_clone.sh- clones an AWS EC2 instance by creating an AMI from the original and then booting a new instance from the AMI with the same settings as the original instance. Useful to testing risky things on a separate EC2 instance, such as Server Administrator recovery of Tableauaws_ec2_instance_wait_for_ready.sh- polls an AWS EC2 instance and waits for it to finish initializing to a ready state. Used by adjacent scriptsaws_ec2_instance_terminate_by_name.sh- terminate an AWS EC2 instance by name for convenience, resolves its instance ID, verifies unique and then terminates by IDaws_ec2_ami*.sh- AWS EC2 AMI scripts:aws_ec2_amis.sh- list AWS EC2 AMIs belonging to your account in an easy to read table outputaws_ec2_ami_ids.sh- lists AWS EC2 AMI IDs only, one per line, to be used in adjacent scripts that creating mapping tables and translate AMI IDs to names in inventory scriptsaws_info_ec2*.shaws_ec2_ami_name_to_id.sh- looks up an EC2 AMI ID from a name with extra safety checks that only a single AMI ID is returned and a reverse lookup on that AMI ID to re-verify it matches the nameaws_ec2_ami_boot.sh- boots a personal EC2 instance of a given AMI for testingaws_ec2_ami_boot_ssh.sh- boots a personal EC2 instance of a given AMI, determines the public or private IP, and drops you into an SSH shellaws_ec2_ami_create_from_instance.sh- creates an AWS EC2 AMI from an EC2 instance and waits for it to become available for useaws_ec2_ami_share_to_account.sh- shares an AMI with another AWS account. Can specify AMI by name or idaws_ec2_ebs_*.sh- AWS EC2 EBS scripts:aws_ec2_ebs_volumes.sh- list EC2 instances and their EBS volumes in the current region- `aws_ec2_ebs_create_snapshot_and_wait.sh - creates a snapshot of a given EBS volume ID and waits for it to complete with exponential backoff
- `aws_ec2_ebs_resize_and_wait.sh - resizes an EBS volume and waits for it to complete modifying and optionally optimizing with exponential backoff
aws_ec2_ebs_volumes_unattached.sh- list an unattached EBS volumes in a table formataws_ec2_launch_templates_ami_id.sh- for each Launch Template lists the AMI ID of the latest version. Useful to check EKS upgrades of node groups via Terragrunt have taken effect
aws_ecr_*.sh- AWS ECR docker image management scripts:aws_ecr_docker_login.sh- authenticates Docker to AWS ECR, inferring the ECR registry from the current AWS Account ID and Regionaws_ecr_docker_build_push.sh- builds a docker image and pushes it to ECR with not just thelatestdocker tag but also the current Git hashref and Git tagsaws_ecr_list_repos.sh- lists ECR repos, and their docker image mutability and whether image scanning is enabledaws_ecr_list_tags.sh- lists all the tags for a given ECR docker imageaws_ecr_newest_image_tags.sh- lists the tags for the given ECR docker image with the newest creation date (can use this to determine which image version to tag aslatest)aws_ecr_alternate_tags.sh- lists all the tags for a given ECR dockerimage:tag(use arg<image>:latestto see what version / build hashref / date tag has been tagged aslatest)aws_ecr_tag_image.sh- tags an ECR image with another tag without pulling and pushing itaws_ecr_tag_image_by_digest.sh- same as above but tags an ECR image found via digest (more accurate as reference by existing tag can be a moving target). Useful to recover images that have become untaggedaws_ecr_tag_latest.sh- tags a given ECR dockerimage:tagaslatestwithout pulling or pushing the docker imageaws_ecr_tag_branch.sh- tags a given ECRimage:tagwith the current Git branch without pulling or pushing the docker imageaws_ecr_tag_datetime.sh- tags a given ECR docker image with its creation date and UTC timestamp (when it was uploaded to ECR) without pulling or pushing the docker imageaws_ecr_tag_newest_image_as_latest.sh- finds and tags the newest build of a given ECR docker image aslatestwithout pulling or pushing the docker imageaws_ecr_tags_timestamps.sh- lists all the tags and their timestamps for a given ECR docker imageaws_ecr_tags_old.sh- lists tags older than N days for a given ECR docker imageaws_ecr_delete_old_tags.sh- deletes tags older than N days for a given ECR docker image. Lists the image:tags to be deleted and prompts for confirmation safety
aws_emr_clusters_last_steps.sh- shows the last N steps executed on each EMR cluster and their EndTime to find idle clusters that should be removed. Also checks CloudWatch for number of steps running within the last few months to catch directly submitted jobs such as Spark, Hive, Glue or Athena which won't show up in the native steps listaws_foreach_profile.sh- executes a templated command across all AWS named profiles configured in AWS CLIv2, replacing{profile}in each iteration. Combine with other scripts for powerful functionality, auditing, setup etc. eg.aws_kube_creds.shto configurekubectlconfig to all EKS clusters in all environmentsaws_foreach_region.sh- executes a templated command against each AWS region enabled for the current account, replacing{region}in each iteration. Combine with AWS CLI or scripts to find resources across regionsaws_iam_*.sh- AWS IAM scripts:aws_iam_password_policy.sh- prints AWS password policy inkey = valuepairs for easy viewing / grepping (used byaws_harden_password_policy.shbefore and after to show the differences)aws_iam_harden_password_policy.sh- strengthens AWS password policy according to CIS Foundations Benchmark recommendationsaws_iam_replace_access_key.sh- replaces the non-current IAM access key (Inactive, Not Used, longer time since used, or an explicitly given key), outputting the new key as shell export statements (useful for piping to the same tools listed foraws_csv_creds.shabove)aws_iam_policies_attached_to_users.sh- finds AWS IAM policies directly attached to users (anti-best practice) instead of groupsaws_iam_policies_granting_full_access.sh- finds AWS IAM policies granting full access (anti-best practice)aws_iam_policies_unattached.sh- lists unattached AWS IAM policiesaws_iam_policy_attachments.sh- finds all users, groups and roles where a given IAM policy is attached, so that you can remove all these references in your Terraform code and avoid this errorError: error deleting IAM policy arn:aws:iam::***:policy/mypolicy: DeleteConflict: Cannot delete a policy attached to entities.aws_iam_policy_delete.sh- deletes an IAM policy, by first handling all prerequisite steps of deleting all pr
README 内容较长,此处已截断,完整内容请查看 GitHub 仓库。