Handy hacks

Handy hacks

Here are a number of scripts here I have found handy over the years:

  • awhich
    which exits when it finds the first occurance of the command in your path. This is a hacked version that gives all occurances of the command. (It's useful to know when there are more than one version of a program.)

  • bytes-per-inode
    Prints out the bytes to inode specified to newfs, and the bytes to inode used as indicated by df.

  • cbackups
    Checks filesystems against /etc/dumpdates to see which filesystems have been dumped and when. You can control what is printed with a .cbackupsrc file in the same directory.

  • check-path-to
    Displays the protection, ownership, and group membership for every element in the path to a specified file or directory. (Useful to check whether someone can or cannot read a file.)

  • clean-known_hosts
    Removes entries from ~/.ssh/known_hosts and known_hosts2 which are covered in the system copy of ssh_known_hosts2. (This is desirable, based on the assumption that the system file is well maintained. Removing outdated entries in these files is a pain for the normal user. And getting them in the habit of doing this breaks the purpose of the files.)

  • convert-to-IP
    Inspired by convert-to-hex (below), this takes a hex argument and outputs an IP address. (Useful when poking around in /tftpboot.)

  • convert-to-hex
    This takes an IP address and converts it to hex (as for the links from /tftpboot). I didn't write this. I forget where I picked it up now.

  • date-to-day
    This takes an date of the form "Apr 5 2001" and outputs the day of week.

  • dig-for-host
    This takes a hostname or an IP address and explicitly traces down the DNS hierarchy, reporting on what each server says about it. It relies on the existence of dig and ping.

  • disk-usage
    This looks at all disks on your system, checking for unallocated space and overlapping partitions. It prints out all partitions and what they're used for. It knows about optical filesystem caches and pieces of metadevices (Online Disksuite). It currently works under SunOS and Solaris.

  • dump-config
    This produces a short document useful for reference when the machine is down. It records such things as the contents of /etc/[v]fstab, /etc/hostname.*[0-9], /etc/domainname, /etc/resolv.conf, as well as the disk configuration as displayed by disk-usage (above). It currently works under SunOS and Solaris.

  • e1p
    Prints a text file, using enscript, on a single page, if possible. (Prints the file in portrait mode unless file is longer than 58 lines, then switches to landscape mode, 2-up).

  • enforce-group-access
    Forces all files and directories beneath a target directory to have the same group as the target directory and be read/write (and execute for directories) accessible to the group. (Useful for cleaning up mistakes in shared directory hierarchies.)

  • jd
    Prints a cumulative of the Julian style date, useful for comparing dates in a script.

  • maintain-home
    Maintains a directory of links to home directories on the system. If these links are used (eg, /fac/home/watrous instead of /fac/u4/watrous), static references to the user's home directory (eg, Netscape preferences or compiled in references in programs) will not break.

  • maxlen
    Prints length of longest line in a file, optionally printing that line. (Useful when some program complains about a line too long.)

  • mem-swap
    Prints amount of available physicel memory for this machine (if available from dmesg), the amount of swap space, and the ratio of swap to memory. It currently works under SunOS and Solaris.

  • netgroup
    So many netgroups are actually hierarchies containing other netgroups. This script recursively enumerates rom the NIS members of a netgroup and its sub-netgroups .

  • rcpdir
    Like cpdir but works (via rrsh) between machines.

  • phost
    Like host but can repetitively try until it gets an answer (or until it fails a specified number of times). Also has a verbose mode.

  • rcpfs
    Like rcpdir (above), can copy remote filesystem on like OS to local filesystem.

  • reconfigure
    On a Sun, does the same thing as "boot -r" (reconfigures devices), but interactively, so a reboot is not needed.

  • rv
    This was inspired by the REV command under Tops-20. Given a list of files/directories, it will present that list one at a time, allowing a number of functions to be performed on each, including (but not limited to) cat, chgrp, chmod, chown, cp, grep, lpr, ls, mv, rm, strings, tail, wc, and zcat. It currently does not stand alone, needing quote.sed and base.sed. I'll try to make it not dependent on separate files at some point.

  • stop-autodismounts
    Prevents automountd from automatically unmounting filesystems already mounted. (Some users are bothered by occasional automount sluggish mounts and/or failures for filesystems they need. With this script running, once the filesystems are mounted, they stay mounted.)

  • tarcom
    tars up and compresses specified directory, leaving results in that directory.

  • tarzip
    Like tarcom above, but uses gzip for compression.

  • untarcom
    Undoes the results of tarcom (above).

  • untarzip
    Undoes the results of tarzip (above).

  • vgroups
    Output like the group command, but puts not loginable groups in square brackets.

  • whatsin
    Consults the DNS to determine what is in a particular room. (Currently works only for Hill Center and CoRE buildings.)

  • whendown
    Same script as whenup (below), but exits when the machine does *not* respond to a ping.

  • whenreboot
    Same script as whenup (below). Logically like whendown followed by whenup for a list of hosts, but it uses rup output to determine if the machine has been rebooted since the script started.

  • whenup
    Given a list of hosts, will do a ping followed by a rup, exiting when both are successful. (Optionally, will exit when there is no change through one cycle.)

  • wheres
    Consults the NIS for the location of a user, or the DNS for the location of a host.
    I also have another list, like this one, of scripts not ready for distribution yet. If you ask nicely, I might make them available. ;^)
    This page last updated March 7, 2006.