Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
# rev 4 - changes suggested by KownBash https://www.reddit.com/r/bash/comments/5cxfqw/i_wrote_a_simple_video_to_gif_bash_script_thought/da19gjz/
# rev 5 - made the script more verbose
# rev 6 - fixed an issue with a variable not displaying correctly
# rev 7 - added option to change dither level
# rev 8 - rewrote usage function
# Usage function, displays valid arguments
usage() {
echo "Usage: $(basename ${0}) [arguments] inputfile" 1>&2
@mplinuxgeek
mplinuxgeek / failed_login.sh
Last active August 16, 2018 00:57
Bash script to check for failed ssh logins and email a report.
#!/bin/bash
# Script requirements lastb, diff, touch, whois, mail.
# To succesfully send an email it will require a working mail configuration
# Tested on Ubuntu 16.04
recipient="[email protected]"
if [ ! -f /root/failed ]; then
touch /root/failed
fi
@mplinuxgeek
mplinuxgeek / Vagrantfile
Last active November 23, 2020 19:14
Vagrantfile to deploy a VM to ESXi, uses Ansible to provision users and install additional packages, also has conditional statements to alter the configuration for different server types
#
# Fully documented Vagrantfile available
# in the wiki: https://github.com/josenk/vagrant-vmware-esxi/wiki
vm_name = File.basename(Dir.getwd)
vm_cpus = '2'
vm_ram = '4'
if vm_name.include? "web"
vm_ram ='2'
end
@mplinuxgeek
mplinuxgeek / tunnel.sh
Last active August 22, 2018 04:32
SSH SOCKS tunnel helper script, opens tunnel, checks that the port is open then launches Firefox, the ssh session closes after 10 seconds which is enough time for Firefox to start but the tunnel will remain open till Firefox is closed.
#!/bin/bash
# SSH SOCKS tunnel helper script, opens tunnel, checks
# that the port is open then launches Firefox, the ssh
# session closes after 10 seconds which is enough time
# for Firefox to start but the tunnel will remain open
# till Firefox is closed.
#
# Changes: MP - 22/08/2018 - Initial version, tested on Ubuntu 18.04 and Windows under Cygwin
#
# Todo: Add proper detection of Cygwin environment
@mplinuxgeek
mplinuxgeek / whois_list.sh
Last active August 23, 2018 01:14
Generate a report of failed login IP's, which country they originate from and the count of each IP. These are generally ssh brute force attempts, I use the report to add new IP's that are brute forcing me to a blocklist on my firewall.
#!/bin/bash
LASTB=$(lastb | awk '{print $3}' | grep -v "192.168.1" | head -n -2 | sort | uniq -c | sed -e 's/^[ \t]*//' | sort -k1nr)
# lastb returns failed login attempts
# print only the 3rd column which has the IP addresses
# grep out local network entries
# remove last 2 lines of the output, lasst line is the date and 2nd last is blank
# sort list for uniq
# uniq -c displays a count of the uniq entries
# remove the leading spaces
# sorts the output using the 1st column from largest to smallest
@mplinuxgeek
mplinuxgeek / fedora-post-install.sh
Last active April 28, 2021 11:27
My post install script to help get Fedora to my desired state.
#!/bin/bash
# If you forgot to set hostname during install like I often do...
sudo hostnamectl set-hostname newhostname
# Remove unneeded (by me) packages
sudo dnf autoremove -y cheese evolution libreoffice-draw libreoffice-impress gnome-maps gnome-clocks gnome-contacts gnome-contacts gnome-weather
# Enable extra repos
sudo dnf install -y fedora-workstation-repositories
@mplinuxgeek
mplinuxgeek / alias
Created August 27, 2018 07:36
youtube-dl aliases
alias youtube-dl-best='youtube-dl -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio" '
alias youtube-dl-480='youtube-dl -f "bestvideo[height<=480][ext=mp4]+bestaudio[ext=m4a]" '
alias youtube-dl-720='youtube-dl -f "bestvideo[height<=720][ext=mp4]+bestaudio[ext=m4a]" '
alias youtube-dl-4k='echo -e "This will transcode the video from webm to h264 which could take a long time\n\n"; youtube-dl -f "bestvideo[ext=webm]+bestaudio[ext=m4a]" --recode-video mp4 '
alias youtube-dl-mp3='youtube-dl --extract-audio -f bestaudio[ext=mp3] --no-playlist '
@mplinuxgeek
mplinuxgeek / sshrc
Last active February 28, 2023 08:26
Script to check the IP address of the SSH session, if it doesn't match the local subnet an email is sent with details of the session and some details of the IP from whois
#!/bin/bash
# Paste this script into /etc/ssh/sshrc
# This runs everytime an ssh session is initiated.
# The script checkes the remote IP address against the local
# subnet, if the subnet is not in the IP address then an
# email is sent containing details about the session and
# some details from whois about the IP address.
#
# Changes: Initial version, tested on CentOS 7
#
@mplinuxgeek
mplinuxgeek / dig
Created August 28, 2018 13:16
dig examples
# Return only the answer
dig +noall +answer youtube.com
youtube.com. 300 IN A 172.217.167.110
# Return only IP address
dig +short youtube.com
172.217.167.110
# Return only the answer from Googles DNS server
dig +short @8.8.8.8 youtube.com
@mplinuxgeek
mplinuxgeek / mkv2mp4.sh
Created September 18, 2018 12:59
Simple script to loop through a directory of MKV's and convert them to MP4's
#!/bin/bash
for file in *.mkv; do
# Extract filename from input file without the extension
filename=$(basename "$file")
#extension="${filename##*.}"
filename="${filename%.*}.mp4"
echo $filename
ffmpeg -i "$file" -codec:v libx264 -preset superfast -crf 22 -vf scale="720:trunc(ow/a/2)*2" -codec:a libfdk_aac -b:a 128k -y "$filename"
done