Subject: Re: mergemaster
To: Martti Kuparinen <>
From: Alistair Crooks <>
List: current-users
Date: 11/14/2001 13:35:54
On Wed, Nov 14, 2001 at 11:52:57AM +0200, Martti Kuparinen wrote:
> Hi!
> I've written a FreeBSD mergemaster-like utility to compare, merge and
> install files into /etc (from /usr/src/etc). Yes, I've read the previous
> "wars" on this subject but I needed a tool to do the config file update...
> This script does NOT check for any CVS tags but runs cmp to find out
> if the file has been updated in /usr/src/etc or not. And if it has,
> the user gets a diff and possibility to merge the currently installed
> and the new version, see the merged version and finally install it.
> So far things have been working quite well, I've updated files in /etc
> and /dev from 1.5.2 to 1.5.3_ALPHA without any problems :-)
> And now the question: how should I get a file's permission in
> a /bin/sh script? I don't want to make this script depend on perl
> but if possible use only standard tools like ls, sed and awk.The uid and gid are
> easily retrieved from ls output but I'd like to avoid
> parsing the "-rwxr-xr-x" strings to produce octal number. But can it be
> avoided?

It's not that drastic using awk: pipe the output from "ls -al" through:

awk '
BEGIN { n["rwx"]="7"; n["rw-"]="6"; n["r-x"]="5"; n["r--"]="4"; n["-wx"]="3"; n["-w-"]="2"; n["--x"]="1"; n["---"]="0"}
{ print "0" n[substr($1,2,3)] n[substr($1,5,3)] n[substr($1,8,3)]}'
(This just proves that awk scripts can be made to look like modem noise too)