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> -hor<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.plLookup IPAs and get hostnamesaddheaderAdd a header at the top of an existing file (very old, arguably crufty and overkill)addltAdd line termination to "one line" HTML filesbenford.shWrite a Benford's Law histogram from input (in pure bash)caps2escMap "caps lock" to "Esc" and back (From http://www.linuxquestions.org/questions/linux-general-1/vim-map-caps-lock-to-escape-409726)changelogTrivial system CHANGELOG wrapper to maintain a/root/CHANGELOG.txt(crufty style)chpermSet owner.group and mode/permissions on a given file in 1 stepclClean Up script, most wiki markup is Zim syntax, but there is Redmine and Jira in there too and some features requirepandocor other external toolscolorsEcho color codes to the screen to see what works (http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html)debwrapper/reminder for various apt* and dpkg commandsdisk-and-partitionsCollect data on disks and partitions, just to havedomath.plPerform math operations on arbitrary lines of numerical inputeditable_menu_shortcutsTurn Gnome editable menu shortcuts on and off (Obsolete?)ff-sess.shSave/Restore FF sessions, with trivial restore GUI (CLI, usingdialog)find-group.plFind a group containing the most users from ausers.txtlist; useful when considering creating a new groups, to see if you might already have a group containing most of the usersfindlargeTrivial reminder/skeleton for finding "large" files in various locationsfindzFind Zombie processes and parent PIDfixbadsigFix BADSIG and other crap in APT repos data (Obsolete?)foregroundBring a named window to the foreground in a GUI, else run it (map it to a keystroke in a GUI)linesortTrivial in-line sort (sort delimited items within a single line, see alsocl)mksshconfTrivial script to make ~/.ssh/config file since you can't #INCLUDEmount-isoTrivial wrapper to mount an ISO imagepdTrivial Pandoc Markdown to HTML or PDF wrapperpick-one.shRandomly choose from a list of optionspivot-by-date.plPivot "Count | Date | Key" columnar data by date and keypivot-key-value.plPivot a key and a value column into a matrixpivot-key-values.pyPivot a key and a comma delimited value column into a matrixpivot.plPivot cells (e.g. columns to rows) in a tableremote-desktopFire up a remote desktop session on the remote side (1-time only, no SSH)read-maillog.plRead 'mail.log' files written by Postfix and report details (quite crufty with hard-coded server names!)rhythmbox-ratings.plMerge "old" ratings into a new Rhythmbox XML filerhythmbox-rm-badpath.plRemove duplicate records with bad path from Rhythmbox XML filerot13.plGuess...rot47.plGuess...ruler.shDisplay a "ruler" across the screensample.plSample a log file to create a smaller filesavepermsSave permissions for a directory structureshow_package_updatesTrivially check for new packages on a Debian-ish system (run from cron, somewhat crufty and experimental)star.plReplace various strings with star "*" to allow use of 'uniq' and other tools (old, crufty, some old CIS bits)split-up.shSplit up a file by writing alternating lines to different filessrpmxExtract files from a source RPM (requiresrpm2cpiobinary, find that elsewhere)sshfswTrivial SSHFS wrapper (SSH File System = FUSE = Awesome!)sysstatDisplay some system stats (e.g. run from cron periodically) (Obsolete? Probably lots of better tools out there!)tattleLog the way this program was called; useful for tracing remote commands such as rsync over SSH.tzTrivial script to convert time zones using GNUdateuntarSimple (GNU) tar wrapperwaitforLikesleepexcept for a random integer period in an arbitrary rangewhatdeb(orwhatrpm) Quick and Dirty find for installed RPMs or DEBszim2wiki.plTrivially convert Zim markup to Redmine or Mediawiki
These are the settings or configs that I use everywhere, every day.
settings/READMEQuick summary of bash init and rc filessettings/bash_logoutClear the screen on logout to prevent information leakssettings/bash_profileLogin shell environment settingssettings/bashrcSubshell environment settingssettings/gitconfigMy typical Git configsettings/inputrcreadline settingssettings/panam-styling-include.css"Fancy CSS" for use with Pandocpdwrappersettings/run_screenWrapper script intended to run from a "profile" file to run screen at logon time with a friendly menusettings/screenrcScreen RC filesettings/vimrcVIM 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_diskGrow a Linux software mirror after swapping in larger hard drivesreplace_mirrored_diskReplace a failed disk in a Linux software mirror