Skip to content

Instantly share code, notes, and snippets.

function mempercent {
total=$(free -m | sed -n '2p' | awk '{print $2}')
used=$(free -m | sed -n '3p' | awk '{print $4}')
echo $(echo $(echo 'scale=2;'$used'/'$total'' | bc)*100 | bc | cut -d'.' -f1)"% memory usage (${used}M Used / ${total}M Total)"
}
function systemload {
loadAverage=$(uptime | cut -d',' -f4 | grep -o "[0-9]*\.[0-9]*$")
processors=$(cat /proc/cpuinfo | grep processor | tail -n1 | awk '{ print $3 }')
let processors=$processors+1
# Scan network range (replace with yours) for MAC addresses, compare with previous scan, and report differences with PushBullet.
# Requires pushbullet bash script from https://github.com/Red5d/pushbullet-bash
touch prev-macs.txt
sudo nmap -sP -n 192.168.1.1/24 | grep "MAC Address" | sort > macs.txt
if [ $(diff macs.txt prev-macs.txt) ];then
pushbullet push all note "New network devices: $(diff macs.txt prev-macs.txt)"
fi
mv macs.txt prev-macs.txt
@Red5d
Red5d / security-setup
Last active August 29, 2015 13:56
Setup basic security for a new server.
#! /bin/bash
echo "Installing basic security..."
apt-get -y install ufw rkhunter fail2ban
ufw allow 22
ufw allow 80
ufw allow 443
ufw enable
@Red5d
Red5d / geoip-restrict
Created February 18, 2014 02:52
This script helps set up GeoIP-based access restriction.
#! /bin/bash
# This script helps set up GeoIP-based access restriction.
# Commands adapted from http://blog.grimneko.de/?p=228
echo "Installing libgeoip-dev, libpam0g-dev, and make (just in case it's not there)..."
sudo apt-get install libgeoip-dev libpam0g-dev make
echo
@Red5d
Red5d / iplookup
Created January 3, 2014 05:21
Use this to look up the Country, State, City, ISP, and Hostname of an IP address (given as parameter) from infosniper.net. Usage: ./iplookup <ip address>
#! /bin/bash
info=$(curl -s http://www.infosniper.net/?ip_address=$1 | grep content-td2 | cut -d'>' -f2 | cut -d'<' -f1 | sed 's/&nbsp;//g')
echo -n "Country: "
echo "$info" | sed -n '10p'
echo -n "State: "
echo "$info" | sed -n '6p'