Skip to content

Instantly share code, notes, and snippets.

View ericwastaken's full-sized avatar

Eric Soto ericwastaken

View GitHub Profile
@ericwastaken
ericwastaken / ssh-forward-start.sh
Last active May 2, 2023 17:18
Shell script to start up an SSH Port Forward to a remote
#!/bin/bash
# *********************************************************************
# script: ssh-forward-start.sh
# summary: Starts an SSH Port Forward process, forwarding a localhost
# port to a remote host. The PID of the SSH process will be saved to
# the file defined in the pid_filename variable.
# See the companion script ssh-forward-stop.sh, which stops the tunnel
# using the process information in the PID file.
#
@ericwastaken
ericwastaken / ssh-forward-stop.sh
Last active October 20, 2017 04:07
Stops a previously started SSH tunnel.
#!/bin/bash
# *********************************************************************
# script: ssh-forward-stop.sh
# summary: Stops an SSH Port Forward process, previously started by
# the companion script `ssh-forward-start.sh`.
#
# Tested on macOS Sierra.
#
# dependencies:
@ericwastaken
ericwastaken / update-files-to-unix.sh
Created October 23, 2017 17:24
Bash script to convert all files in a directory, recursively, to Unix format
# Run from the root of the directory that contains files and subdiirectories.
# Dependencies: find, dos2unix
# Fina all files, then execute dos2unix on them
find . -type f -exec dos2unix "{}" \;
@ericwastaken
ericwastaken / list-non-unix-files.sh
Created October 23, 2017 17:34
List files that don't have Linux file endings
# Run from the root of the directory that contains files and subdirectories.
# Dependencies: find, file
# Fina all files, then execute FILE on them, filter for the string 'CRLF'
find . -type f -exec file "{}" \; | grep CRLF
@ericwastaken
ericwastaken / logalert.sh
Last active November 4, 2017 19:43
A simple script that scours logs (incrementally) looking for keywords and emails you if it finds at least 1 of your keywords. Perfect to be scheduled with CRON since it uses logtail to scan only parts of logs that it has not scanned before!
#!/bin/bash
####
# Scours log files for keywords, then and emails
# if it finds them.
#
# This script also has keywords to exclude. This is, within the matches
# if the exclude keywords appear, then those lines are excluded from
# the output report. This allows you to "match" on a long keyword (
# e.g. "/some/directory/with/tools") yet exclude a specific match (
@ericwastaken
ericwastaken / download-url-list.sh
Created February 16, 2018 20:01
Download all URLs in a list (using wget)
#!/bin/bash
echo ""
echo "E.A.Soto"
echo "Downloads each URL in a list into local files, first creating a 'downloads' directory in the current directory."
echo "Syntax: $0 [path-to-list]"
echo ""
# Check for parameters
if [[ -z $1 ]]; then
@ericwastaken
ericwastaken / filetoiplist.sh
Created March 21, 2018 00:48
Given the file path of a file has a hostname per line, looks up the IP for each host
#!/bin/sh
# *********************************************************************
# script: filetoiplist
# summary: given a file path (assuming it has a host per line), looks
# up the IP for each host.
# dependencies: host; grep
# by: e.a.soto, eric@issfl.com
#
# history
@ericwastaken
ericwastaken / geturilist.sh
Created March 21, 2018 00:52
given a passed URL, extracts all URIs and returns a list, sorted and unique.
#!/bin/sh
# *********************************************************************
# script: geturilist
# summary: given a passed URL, extracts all URIs and returns a list,
# sorted and unique.
# dependencies: wget; grep
# by: e.a.soto, eric@issfl.com
#
# history
@ericwastaken
ericwastaken / gethostlist.sh
Created March 21, 2018 00:53
Given a passed URL, extracts all hosts and returns a list, sorted and unique.
#!/bin/sh
# *********************************************************************
# script: gethostlist
# summary: given a passed URL, extracts all hosts and returns a list,
# sorted and unique.
# dependencies: wget; grep
# by: e.a.soto, eric@issfl.com
#
# history
@ericwastaken
ericwastaken / filetopingreply.sh
Last active March 21, 2018 00:57
Given a file path that has a hostname per line, uses another script to get the IP for each host then tries an ICMP ping and returns those that reply
#!/bin/sh
# *********************************************************************
# script: filetopingreply
# summary: given a file path (assuming it has a host per line), uses
# another script to get the IP for each host then tries
# an ICMP ping and returns those that reply
# NOTE: Backgrounds each PING to perform these faster!
# dependencies: filetoiplist (in same path as this script); grep
# by: e.a.soto, eric@issfl.com