Skip to content

Instantly share code, notes, and snippets.

@eusonlito
eusonlito / 0_reuse_code.js
Last active August 29, 2015 14:19
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@eusonlito
eusonlito / ddos-filter.sh
Last active June 26, 2023 04:29
This script check netstat connected IPs with more than $limit connections. If connections continues 5 minutes after, IP will be added to iptables with DROP.
#/bin/bash
# This script check netstat connected IPs with more than $limit connections
# If connections continues 5 minutes after, IP will be added to iptables with DROP
# Execute as cron every 5 minutes
# */5 * * * * /root/shells/ddos-detect.sh >> /root/logs/ddos-detect.log 2>> /root/logs/ddos-detect.err
echo ""
echo "Start at: `date "+%Y-%m-%d %H:%M:%S"`"
#!/bin/bash
# -------------------------------------
# Script to do incremental rsync backups
# from a central backup server
#
# This script is freely distributed under the GPL
# -------------------------------------
# -------------------------------------
@eusonlito
eusonlito / raspberry-pi-backup.sh
Created October 27, 2015 10:12
Create Raspberry Pi backups using a script launched as a cronjob
#!/bin/bash
# Cron installation:
# 30 05 * * * /root/scripts/raspberry-pi-backup.sh >> /root/logs/raspberry-pi-backup.log 2>&1
# Configuration
external="/backup" # Check if external storage is mounted
folder="$external/raspi" # Base backup folder
dev="/dev/mmcblk0" # Device to backup
days=10 # Delete backups older than X days
@eusonlito
eusonlito / add-keys-to-servers.sh
Last active July 1, 2022 01:07
Adds new SSH Keys to multiple servers and checks the connection. SSH Keys will not be duplicated if exists.
#!/bin/bash
# Install: Download and add execution permissions
#
# Usage: ./add-keys-to-servers "current-private-key-to-connect" "new-private-key-to-add" "servers.list"
#
# First parameter must be the current available key to connect to servers
# Second parameter must be the new key to add to servers
# Third parameter must be the servers list (One line for server with format: hostname,port)
@eusonlito
eusonlito / hdd-wakeup.sh
Last active December 4, 2015 11:59
Used on Raspberry Pi installation to avoid access problems with sleep and energy save policies. Installed as cron every minute.
#!/bin/bash
# crontab -e
# * * * * * /root/scripts/hdd-wakeup.sh >> /root/logs/hdd-wakeup.log 2>&1
devices=$(mount -l | grep -o '/dev/sd[a-z][0-9]')
if [ "$devices" == "" ]; then
echo "$(date "+%Y-%m-%d %H:%M:%S") No HDD mounted"
exit 1
@eusonlito
eusonlito / backup-mysql.sh
Last active June 26, 2023 04:25
Automate your MySQL backups
#!/bin/bash
# -------------------------------------
# Databases backup with X days storage history
#
# User executing this script must have FULL permissions
# to mysql and mysqldump
#
# Use $HOME/.my.cnf to store MySQL auth
#
@eusonlito
eusonlito / bash-prompt.sh
Last active April 22, 2021 10:31
Simple bash promp configuration
## User installation:
#
# 1) Append to user file ~/.bashrc
#
# Wide System installation:
#
# 1) Create /etc/bash.bashrc.d folder
# 2) Paste this file into /etc/bash.bashrc.d/custom.sh file
# 3) Append ". /etc/bash.bashrc.d/custom.sh" at end of /etc/bash.bashrc file
#
@eusonlito
eusonlito / goaccess.sh
Last active September 27, 2016 11:01
Goaccess install into Ubuntu Xenial
# Add goaccess repository
echo "deb http://deb.goaccess.io/ xenial main" > /etc/apt/sources.list.d/goaccess.list
# Add repository keys
gpg --keyserver keyserver.ubuntu.com --recv-key 742483B7B222C443
gpg -a --export 742483B7B222C443 | apt-key add -
# Update apt
apt-get update
@eusonlito
eusonlito / local-backup.sh
Last active June 26, 2023 04:25
Easy backup script into a local computer
#!/bin/bash
# -------------------------------------
# Script to do incremental rsync backups
# into a local computer
#
# This script is freely distributed under the GPL
# -------------------------------------