Skip to content

Instantly share code, notes, and snippets.

@isaaclw
isaaclw / wordle.sh
Last active November 27, 2022 15:11
wordle
#!/bin/bash
INCLUDE=
EXCLUDE=
COUNT=
while getopts ":i:e:m:ch" flag; do
case $flag in
i|include) INCLUDE="$OPTARG";;
e|exclude) EXCLUDE="$OPTARG";;
c|count) COUNT=1;;
@isaaclw
isaaclw / random_words
Created November 25, 2019 15:02
List 10 random words #bash
#!/bin/bash
WORDFILE="/usr/share/dict/words"
NUMWORDS=10
#Number of lines in $WORDFILE
tL=`awk 'NF!=0 {++c} END {print c}' $WORDFILE`
for i in `seq $NUMWORDS`; do
rnum=$((RANDOM%$tL+1));
sed -n "$rnum p" $WORDFILE;
@isaaclw
isaaclw / rebootgrub2os.sh
Created November 22, 2019 16:37
Reboot Grup to the specific OS you specify #grub #bash
#!/bin/bash
if ! grep "GRUB_DEFAULT=saved" /etc/default/grub > /dev/null; then
sudo sed -i 's/^GRUB_DEFAULT=.*/GRUB_DEFAULT=saved/' /etc/default/grub
fi
echo
echo "== SELECT WHICH OS TO BOOT =="
echo
sudo cat /boot/grub/grub.cfg | grep -oE "^menuentry '[^']+'" | awk -F\" '{print N++,$(NF-1)}'
@isaaclw
isaaclw / replace_text
Created November 22, 2019 16:37
Replaces a string within multiple files specified on the command line #perl
#!/usr/bin/perl
#
# Replaces a string within multiple files
# specified on the command line
$mv = '/bin/mv';
$tmp = '/tmp';
$op = shift || die("Usage: $0 perlexpr [filenames]\n");
@isaaclw
isaaclw / wordpress_upload_daemon.sh
Last active November 22, 2019 20:51
Wordpress Upload Daemon #bash #wordpress #ftp
#!/bin/bash
SHARE='/opt/shuttle'
FROM_FOLDER="$SHARE/Ready to Transfer"
TRANS_FOLDER="$SHARE/Transferred"
ERROR_FOLDER="$SHARE/Didnt Upload"
mkdir -p "$FROM_FOLDER" "$TRANS_FOLDER" "$ERROR_FOLDER"
# The idea is that files show up in $FROM_FOLDER, and are uploaded via ftp to the wordpress folder.
# If they transfer successfully, they're moved to $TRANS_FOLDER
# If they fail, they're tranferred to $ERROR_FOLDER
@isaaclw
isaaclw / dehardlink.sh
Created November 22, 2019 15:45
Copy and unlink files #bash #fs
@isaaclw
isaaclw / forcefsck
Created November 22, 2019 15:41
Force fsck #ubuntu #bash
sudo touch /forcefsck
sudo shutdown -r 1 "shutting down to do disk check"
@isaaclw
isaaclw / sudo_envcat
Last active May 28, 2020 15:47
Checks a Pid for a variable in the environment #bash #env
#!/bin/bash
# isaac ALL = NOPASSWD: /home/isaac/.bin/sudo_envcat
pid="$1"
if [ "$pid" == 't' ] && [ $(whoami) == 'root' ]; then
exit 0
fi
var="$2"
output=$(cat /proc/$pid/environ | tr '\0' '\n' | grep "$var" | cut -d '=' -f2-)
if [ -n "$DEBUG" ] && [ -n "$output" ]; then
@isaaclw
isaaclw / parse_download.pl
Last active September 7, 2020 03:12
Parse page (with perl) and then download everything matching a regex. #perl #download
#!/usr/bin/perl
# download a page, and then download all the files on the page according to the regular expression, and store them in the folder
use strict;
use URI::URL;
my $urlchars = "[^\'\"]";
parse("http://www.test.com/", "data-bt=\"($urlchars*?\.torrent)\"", "humble");
sub parse() {
@isaaclw
isaaclw / curl_cookies.sh
Last active November 22, 2019 16:06
Run Curl with cookies
#!/bin/bash
COOKIE_JAR=cookies.txt
URL="http://www.google.com/foobar/"
get_session() {
read -p "username: " username
# The -s option is only present in bash
read -sp "password: " password