Useful scripts

mjollnir

Active Member

Reaction score: 61
Messages: 225

Hi people!
Please, post here useful scripts which can help to do some useful or difficult operation on FreeBSD OS.
Found a script on one of my old laptops to attach/insert a geom(4) I/O scheduler - RTFM gsched(8).
  • An I/O scheduler is at least useful on a UFS (or alike) system; I don't know and didn't try with ZFS. Other use cases might be a DB on a dedicated geom(4) device.
  • The I/O scheduler can significantly increase throughput and interactivity with concurrent tasks, as described by the authors of gsched(8).
    I can could verify that - the system runs much "smoother" when running background tasks with heavy disk I/O. The script served me well for years.
  • The script might violate some guidelines for rc scripting that I was not aware of.
  • Very Likely it has bugs, since I was the only user.
    Drop me a note and I'll fix that.
  • If a few others could prove it's safe, it could go to /usr/share/examples/etc/rc.d or even in the base.
  • Suggested directories:{/usr/local}/etc/rc.d/geom_sched, {/usr/local}/libexec/fs_summarize.awk
    or the respective directories in /usr/share/examples
    and rc.geom_sched.conf is for insertion in rc.conf{.local}
The other script fs_summarize.awk is useful to determine the parameters for newfs(8) or just if you want some info about a FS or directory.
Just in case this is needed: the standard FreeBSD BSD license applies to the scripts, the snippet rc_geom_sched.conf obviously does not need any license.
 

Attachments

kpedersen

Daemon

Reaction score: 765
Messages: 1,760

Moving UNIX domain sockets
Not really a script as such but more an example that UNIX domain sockets can be moved (not copied). This is really handy for allowing X11 access into a Jail.

Code:
UNIQUE=$$
Xephyr :$UNIQUE &

# Wait until the socket exists

mv /tmp/.X11-unix/X$UNIQUE /jails/myjail/tmp/.X11-unix/X0
jexec myjail xterm -display :0
Finding absolute path of script or program
Also, a handy way to get the absolute path to your script (or more usefully, the prefix) without faffing with procfs and all that other stuff. This is useful because sometimes relative paths are not supported or not desired.

Code:
PREFIX="$(cd "$(dirname "$(which "$0")")" && cd .. && pwd)"

# which "$0" ensures that a path is returned if the program was run from $PATH
# dirname ensures that the directory containing the program (i.e bin) is returned
# cd, cd .., pwd ensures that an absolute path is given by going into the directory and using pwd.
It seems a bit "dirty" but I also use this (via popen) in C++ and perl. It is the only guaranteed way that I have found over the years. And I have tried quite a few!
 
Top