Various useful utils and bash settings
Do not run any of this code without reading and understand it!
This is the "local" code I sync to all the nodes I manage. Some of it is not production quality and I wrote some of it decades ago, so there may be better ways or better tools. But it's what I have. I share it in case it's useful to someone else. Some of the ideas may have come out of the Bash Cookbook but some of them went into it. Some of the code came right off the internet, and some was adapted; either should be cited.
I sync it to /opt/bin/
because that's reasonably discoverable and short, system-wide, yet distinct from /usr/local/bin/
or similar. I keep it in Subversion because I like keyword expansion and do not like Git, so I use both svn
and git
together to only publish what I want to here.
Some of the code or settings might make sense only to me or my environment, so read the code first. In particular, drake
is my internal "services" server and hamilton
is my mail relay, both are references to authors I like, and not musical. Also, there might be code derived from or handlers for $WORK things, in particular Counterpane (CIS). Since that tech is now defunct I'm not going to worry too much.
Just clone the repo someplace and use whichever files you want. Do not run any of this code without reading and understand it!
- Try
<PROGRAM> -h
or<PROGRAM> --help
(works for most, but not all!) - Read the code
The cl
"clean Up script" is probably the most handy tool I have. It's a filter that reads from the GUI clipboard, does some arbitrary thing, then writes the results back to the GUI clipboard. It does almost all the things for me but it's an odd work-flow. I like it because I can make it to arbitrary things using bash or Perl one-liners, and I'm not stuck with 37 different macro languages. Whatever GUI tool I happen to be using: select > copy > ALT-TAB to terminal > cl whatever
> ALT-TAB back > paste.
DNSlookup.pl
Lookup IPAs and get hostnamesaddheader
Add a header at the top of an existing file (very old, arguably crufty and overkill)addlt
Add line termination to "one line" HTML filesbenford.sh
Write a Benford's Law histogram from input (in pure bash)caps2esc
Map "caps lock" to "Esc" and back (From http://www.linuxquestions.org/questions/linux-general-1/vim-map-caps-lock-to-escape-409726)changelog
Trivial system CHANGELOG wrapper to maintain a/root/CHANGELOG.txt
(crufty style)chperm
Set owner.group and mode/permissions on a given file in 1 stepcl
Clean Up script, most wiki markup is Zim syntax, but there is Redmine and Jira in there too and some features requirepandoc
or other external toolscolors
Echo color codes to the screen to see what works (http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html)deb
wrapper/reminder for various apt* and dpkg commandsdomath.pl
Perform math operations on arbitrary lines of numerical inputeditable_menu_shortcuts
Turn Gnome editable menu shortcuts on and off (Obsolete?)ff-sess.sh
Save/Restore FF sessions, with trivial restore GUI (CLI, usingdialog
)find-group.pl
Find a group containing the most users from ausers.txt
list; useful when considering creating a new groups, to see if you might already have a group containing most of the usersfindlarge
Trivial reminder/skeleton for finding "large" files in various locationsfindz
Find Zombie processes and parent PIDfixbadsig
Fix BADSIG and other crap in APT repos data (Obsolete?)foreground
Bring a named window to the foreground in a GUI, else run it (map it to a keystroke in a GUI)linesort
Trivial in-line sort (sort delimited items within a single line, see alsocl
)mksshconf
Trivial script to make ~/.ssh/config file since you can't #INCLUDEmount-iso
Trivial wrapper to mount an ISO imagepd
Trivial Pandoc Markdown to HTML or PDF wrapperpivot-by-date.pl
Pivot "Count | Date | Key" columnar data by date and keypivot-key-value.pl
Pivot a key and a value column into a matrixpivot.pl
Pivot cells (e.g. columns to rows) in a tableremote-desktop
Fire up a remote desktop session on the remote side (1-time only, no SSH)read-maillog.pl
Read 'mail.log' files written by Postfix and report details (quite crufty with hard-coded server names!)rhythmbox-ratings.pl
Merge "old" ratings into a new Rhythmbox XML filerhythmbox-rm-badpath.pl
Remove duplicate records with bad path from Rhythmbox XML filerot13.pl
Guess...rot47.pl
Guess...ruler.sh
Display a "ruler" across the screensample.pl
Sample a log file to create a smaller filesaveperms
Save permissions for a directory structureshow_package_updates
Trivially check for new packages on a Debian-ish system (run from cron, somewhat crufty and experimental)star.pl
Replace various strings with star "*" to allow use of 'uniq' and other tools (old, crufty, some old CIS bits)split-up.sh
Split up a file by writing alternating lines to different filessrpmx
Extract files from a source RPM (requiresrpm2cpio
binary, find that elsewhere)sshfsw
Trivial SSHFS wrapper (SSH File System = FUSE = Awesome!)sysstat
Display some system stats (e.g. run from cron periodically) (Obsolete? Probably lots of better tools out there!)tattle
Log the way this program was called; useful for tracing remote commands such as rsync over SSH.tz
Trivial script to convert time zones using GNUdate
untar
Simple (GNU) tar wrapperwaitfor
Likesleep
except for a random integer period in an arbitrary rangewhatdeb
(orwhatrpm
) Quick and Dirty find for installed RPMs or DEBszim2wiki.pl
Trivially convert Zim markup to Redmine or Mediawiki
These are the settings or configs that I use everywhere, every day.
settings/README
Quick summary of bash init and rc filessettings/bash_logout
Clear the screen on logout to prevent information leakssettings/bash_profile
Login shell environment settingssettings/bashrc
Subshell environment settingssettings/inputrc
readline settingssettings/panam-styling-include.css
"Fancy CSS" for use with Pandocpd
wrappersettings/run_screen
Wrapper script intended to run from a "profile" file to run screen at logon time with a friendly menusettings/screenrc
Screen RC filesettings/vimrc
VIM RC file
Do not run any of this code without reading and understand it! These can trash your hard drives and destroy all your data! They worked for me, for how I set things up and how I do things. Do not run these without understanding exactly what they do and modifying them to fit your environment! You have been warned.
grow_mirrored_disk
Grow a Linux software mirror after swapping in larger hard drivesreplace_mirrored_disk
Replace a failed disk in a Linux software mirror