Skip to content

Instantly share code, notes, and snippets.

View ericwastaken's full-sized avatar

Eric Soto ericwastaken

View GitHub Profile
@ericwastaken
ericwastaken / nc-ps.ps1
Created March 29, 2024 01:10
NetCat (nc) very simple clone on Powershell
<#
.SYNOPSIS
Checks if a specified port on a given hostname is open or closed, with a simplified output.
.DESCRIPTION
This script uses the Test-NetConnection cmdlet to attempt a TCP connection to a specified hostname and port.
It then checks the result of this attempt to determine if the port is open (indicating the host is listening on that port)
or if the port is closed/not reachable. The result is printed to the console with a color-coded message.
.PARAMETER hostname
@ericwastaken
ericwastaken / run-script-at-interval.ps1
Created July 30, 2023 04:39
Powershell run script at interval
######################################################################
# Runs another powershell script at a given interval.
# Syntax:
# .\run-script-at-interval.ps1 [script path] [interval in seconds]
# Example:
# .\run-script-at-interval.ps1 .\script-to-run.ps1 60
######################################################################
param (
[string]$ScriptPath,
@ericwastaken
ericwastaken / ps-post-benchmark.ps1
Last active July 30, 2023 04:09
Powershell Request Post Benchmark (Powershell CURL POST benchmark alternative)
##########################################################
# ps-post-benchmark.ps1
#
# A powershell script to make a POST to a remote URI
# and measure the response time.
#
# Useful when a client only has Powershell.
#
# Copyright 2023 eric@issfl.com
#
@ericwastaken
ericwastaken / DockerCheatSheet.md
Last active July 10, 2023 19:58
A Docker / Docker Compose Cheat Sheet

Docker / Docker Compose Cheat Sheet

Docker

Add this to Dockerfile to add aliases of your choice (works for images that have /bin/bash)

# Add alias to user profile
RUN echo "alias ll='ls -la'" >> /root/.bashrc
@ericwastaken
ericwastaken / How-to-load-an-environment-file-in-bash.md
Last active April 16, 2022 06:09
An example Bash script that reads variables from an environment file

An example Bash script that reads variables from an environment file

This will load variables into a BASH SCRIPT from an environment file.

Create an environment file with the following structure. Call it "secrets.env" but it can be called anything!

MY_SECRET="Some Secret"
@ericwastaken
ericwastaken / dump-query-template.env
Last active April 16, 2022 06:07
Shell script interface for Elasticsearch Dump
# Pass headers into Elasticsearch:
# - Authorization can be used to pass BASIC AUTH with a TOKEN. Use
# a tool of your choice to convert your username/password into
# the proper token for basic auth.
ED_HEADERS='{"Authorization": "Basic YOUR-BASIC-AUTH-TOKEN-HERE"}'
# Host must end in "/"
# Include ":port-number" if necessary (otherwise, 443 is inferred by https)
ED_HOST="https://your-host.com:port-number/"
@ericwastaken
ericwastaken / delete-child-directory-contents.sh
Last active November 7, 2020 02:52
A BASH script to delete the contents of all child directories in the current path while retaining the child directories themselves.
#!/bin/bash
############################################################################
# This script iterates over each child directory from where it runs
# and deletes ALL contents of those child directories, while leaving
# the directory itself intact.
#
# Copyright 2020 Eric A. Soto, eric@issfl.com
#
# Permission is hereby granted, free of charge, to any person obtaining a
@ericwastaken
ericwastaken / Running an ad-hoc command on multiple hosts using ansible.md
Last active October 10, 2023 20:23
Running ad-hoc Commands and Scripts on multiple hosts using Ansible

Running ad-hoc Commands and Scripts on multiple hosts using Ansible

Summary

Ansible is very helpful for automated deployments. However, it can also be used for server admin tasks against many servers by using both the Command, Shell and Script Modules.

Note: Although the process described here works with hosts that you can access via password or SSH keys, it is more convenient when working with hosts that you have SSH keys for (you don't have to enter passwords!)

License

@ericwastaken
ericwastaken / s3-setup.md
Last active November 7, 2020 02:57
How to create an S3 Bucket with Programmatic Access

How to create an S3 Bucket with Programmatic Access

Summary

This post explains how to create an AWS S3 Bucket and an IAM User with programmatic access to the bucket.

You will need access to the AWS S3 console for your account and have permissions to create new buckets and create new IAM users.

This is based on:

@ericwastaken
ericwastaken / Manual Snapshot (Backup) of an Elastic Cloud instance.md
Last active November 7, 2020 02:57
Manual Snapshot (Backup) of an Elastic Cloud instance to AWS S3