Skip to content

Instantly share code, notes, and snippets.

@mplinuxgeek
mplinuxgeek / iperf.service
Last active November 18, 2019 09:48
/etc/systemd/system/iperf.service
[Unit]
Description=iperf server
After=syslog.target network.target auditd.service
[Service]
ExecStart=/usr/bin/iperf -s
[Install]
WantedBy=multi-user.target
@mplinuxgeek
mplinuxgeek / not_a_real_script.sh
Created October 21, 2019 11:57
Installing hassio on Fedora
$ sudo dnf install jq curl avahi dbus-daemon docker cockpit-docker
$ sudo systemctl enable docker
$ sudo systemctl start docker
$ sudo firewall-cmd --permanent --add-port=8123/tcp
$ sudo firewall-cmd --permanent --add-port=1883/tcp
$ sudo firewall-cmd --reload
$ sudo curl -sL https://raw.githubusercontent.com/home-assistant/hassio-installer/master/hassio_install.sh | bash -s
esphome:
name: ws2812
platform: ESP8266
board: d1_mini
wifi:
ssid: ''
password: ''
mqtt:
@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
@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 / 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 / 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 / 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 / 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 / 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