Shell Scripts
If you don't know what "shell script" means, this page will hold nothing of interest for you, otherwise...
This page is a dumping ground for Unix-style shell scripts which
are general-purpose enough to be worth posting online. Note that the
downloadable files are all given .txt
extensions
because some browsers like to warn about "potentially dangerous"
content when downloading files with extensions like
.sh
.
The Obligatory Disclaimer: the scripts on this page are published here with the hope that they might be useful to someone out there. Do not run scripts you do not understand, especially those handed out by random people on the internet, because That Way Lies Malware. Any and all responsibility for what these scripts do (or don't do) to your system lies with you, not me.
Makeup: "upwards-recursive" make
wrapper
Problem: it's common for me to work in emacs in source
trees which don't have makefiles in every subdirectory. Tapping (ctrl-x
m) to run make
annoyingly (but rightfully) fails in such
directories.
Solution: this bash script works like a drop-in replacement
for make
except that... It looks in the current
directory for a makefile. If it finds one, it
runs make
, else it moves up one directory and tries
again, until either it's out of directories to try or it hits a
directory it can't enter. Mapping this script to
emacs's compile-command
var solves the "no makefile
found"-from-emacs problem for me. (i should have done this two
decades ago :|.) Any arguments passed to the script are passed on
as-is to the underlying make
call.
Script: makeup.bash.txt (1657 bytes, last modified May 19, 2019)
Be sure to read the script and edit, if
needed, the location of the real make
binary. It is not
determined dynamically (using "which make") because this script
might be named "make", in which case it would find and call itself
recursively. (It was a quick hack, not an industrial-strength
solution.)
throttlecpu: set the max CPU speed from the CLI
Problem: i'm somewhat over-sensitive to computer fan noise. My main computer, when it's allowed to run at full speed, will often turn on the fan to cool it down.
Solution: slow down the CPU. There are many ways to do this,
including desktop applets. This particular bash script expects
to be passed a number - the desired maximum CPU speed in megaherz -
and it sets that to the maximum speed for all CPUs. It requires the
cpufrequtils
. This script makes no effort to keep the
number passed to it within the limits of the CPUs - it assumes the
user (that'd be me) knows the limits of their machine. (Though
slowing down the CPU might seem silly to some, 2.4ghz is plenty of
speed for 98% of what i do. i only jack it all the way up when i'm
particularly interested in benchmarking something, which is a very
rare case for me.)
Script: throttlecpu.txt (633 bytes, last modified September 17, 2022)
ffrecode: a basic CPU-throttled ffmpeg
wrapper
Problem: i often recode videos, e.g. those taken with my
phone, because doing so often compresses them to anywhere from 25%
to 80% of their original size (why my phone can't do that in real
time, i don't know). When recoding video using ffmpeg
,
it likes to peg all of my CPUs at 100% (thus the "peg" in "ffmPEG"),
causing the loud fans to kick in or even, for longer encoding,
overheating the system. The -threads
option ffmpeg
offers has never worked for me: it still
pegs all CPUs even when told to use only a single thread.
Solution: The cpulimit
utility can be used to
throttle CPU-hogging apps like ffmpeg
. This script
wraps ffmpeg
in cpulimit
and converts its
input files to MP4 files with the .mp4
extension. When
encoding MP4 files, rename the input files to have a different
extension (e.g. .mpg
) before passing them to this
script, or it will complain and exit: it does not risk causing
confusion or data loss by renaming your input files. (It's not
terribly clever in that regard, but it gets the job done for me.) It
does not do any adjustment of video resolution or whatnot: it simply
recodes from whatever the input is to MP4. For MP4 input is may or
may not decrease the size of the input, depending entirely on how
the video was initially encoded. For some MP4 files it may produce
larger output, but that's relatively rare.
Script: ffrecode.bash.txt (1924 bytes, last modified May 26, 2020)
Be sure to read and adjust the script, in
particular changing the limitpct
variable to match your
system's limits (lowering or raising it, as desired: finding a suitable
value may require some experimentation).
pdf2cbz: convert PDF to CBZ (Comic Book Zip) format
Problem: digital comic books, a.k.a. "sequential art," come in many formats, one of which is PDF. As i consider that to be a poor format for the various mobile-device comic book readers, i convert all such PDFs to CBZ format, which is just a ZIP file containing image files, one per page of the book. A related format is CBR, which uses RAR archives instead of ZIP, but that just seems silly to me given the ubiquity of ZIP archive support.
Solution: the attached script uses the ImageMagick tools to convert a single PDF to a CBZ file. It uses JPG image format by default can be configured to use PNG and to change the image DPI density (see the script for details).
Script: pdf2cbz.bash.txt (653 bytes, last modified June 28, 2024)