I needed a command-line method of creating a file whose size in bytes is the percentage of free space on a disk. I intend to run it via cron every five minutes, but first a shell script will do.
The target platform is the BSD4.3 environment in DOMAIN/OS, so I have ksh
, awk
, sed
and the usual BSD commands, but not GNU versions.
I can run a command lvolfs -a
(not a BSD command) which lists volume free space in this format:
# free # total % free node id entry directory
732532 1295672 57 4D72C /
3787184 4165732 91 52055 //tr3
-------------------------------
4519716 5461404 82.76% 2 volumes.
so it seems straightforward to extract the values, in this case 57 and 91, identifying them by the hexadecimal node ids, 4D72C and 52055, respectively.
I immediately thought 'dd can do it', so concentrating on node 4D72C first, I came up with:
/com/lvolfs -a | \
awk -e '/4D72C/ { print $3 }' | \
sed -e 's|^|dd if=/dev/rdsk of=//tr2/test/data/tr2.free bs=|' | \
sed -e 's|$| count=1|' >//tr2/archive/dirlist
. //tr2/archive/dirlist
And dirlist
looks like
dd if=/dev/rdsk of=//tr2/test/data/tr2.free bs=57 count=1
It works, and I'll need to repeat something like this for node 52055, but I wonder if dd
is the only way using really basic BSD commands. Would anyone have any suggestions?
EDIT: Some more background information about the target system ... it's an HP/Apollo DN433 'Engineering Workstation', the bee's knees when it was released in the early '80s, but now about as impressive as a 486DX system. The native OS attempts to imitate Unix by providing a BSD4.3 'environment' with a reasonable set of BSD commands, but there is a temptation to mix BSD and Aegis commands (like lvolfs
) as I've done here.
I have two workstations, and each controls Automatic Test Equipment. The two workstations are networked together and the network root directory //
includes tr2 (node id 4D72C) and tr3 (node id 52055). You don't really want or need to know all this stuff - I'd just like to give the impression that nothing should be taken for granted. I don't want anyone to waste too much time on this stuff - that's my job, but I'd appreciate any suggestions you might have. The Korn Shell is still a bit of a mystery to me.
UPDATE: The df -a
command in DOMAIN/OS gives
$ df -a
Filesystem kbytes used avail capacity Mounted on
/dev/wn96a 1295672 563904 731768 44% //tr2
/dev/wn96a 4165732 379804 3785928 9% //tr3
----------------------------------
5461300 943700 4517600 17%
Which, since it mentions the more familiar names tr2 and tr3, might be preferable. The only slight hurdle is that we get disk space used not free, but this can be overcome.