Skip to content

Instantly share code, notes, and snippets.

View cpedro's full-sized avatar

Chris Pedro cpedro

View GitHub Profile
@cpedro
cpedro / zero_mbr.sh
Created September 15, 2021 15:45
Zero out the MBR on a Linux Server
sudo dd if=/dev/zero of=/dev/sda count=1 bs=512
@cpedro
cpedro / remove_older_than.sh
Last active September 17, 2021 14:46
Bash function to find all files and directories in the current director older than <days> and remove them.
# Find all files and directories in the current director older than <days> and remove them.
function remove_older_than () {
if [[ "$#" -eq 0 || ! "$1" =~ ^[0-9]+$ ]]; then
echo "usage: remove_older_than <days>"
return
fi
find . -ctime +${1} -type f -exec rm -f {} \;
find . -ctime +${1} -type d -exec rm -rf {} \;
}
@cpedro
cpedro / getcert.sh
Last active September 7, 2021 12:36
Bash function to download a certificate from a server using OpenSSL
function getcert()
{
local host=${1:-}
local port=${2:-443}
if [ -z ${host} ]; then
echo "usage: getcert <server> [<port>]"
echo " <port> will default to 443 if not given."
return
fi
echo | openssl s_client -servername ${host} -connect ${host}:${port} | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ${host}.crt
@cpedro
cpedro / colour_codes.sh
Created January 28, 2020 18:16
Print out colours in a enabled terminal
#!/usr/bin/env bash
# Simple script to print out some colour codes to the terminal to show
# what's available. This can be expanded to included more codes easily
# by editing the for loops.
echo
echo "Prepend code with \\e["
for attr in {0..5} 7
do
for fgcl in {30..37}
@cpedro
cpedro / git-refs
Created July 19, 2019 21:39
Print git refs on a repo in pretty format.
#!/bin/bash
# File: git-refs
printf "\e[1;34m${PWD}\e[0m"
fmt='
%(color:bold cyan)%(refname:short)%(color:reset):
Commit: %(color:yellow)%(objectname)%(color:reset)
Date: %(committerdate:format:%Y-%m-%d %H:%M:%S)
Committer: %(committername) %(committeremail)'