Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I get the list of local domains from a forward file?

An example of /etc/exim4/forwards:
# ignore this line

Here the string expansion (or what ever it's called g) should return :

I assume it can be done with readfile and map, but I can't get it to work.

share|improve this question

I have something that almost works the way you want it. What this expansion does is:

  1. Slurp in the file, using ; as the separator.
  2. Exclude any lines with # in them (i.e. comments).
  3. It should skip blank lines, but my regex isn't matching, it still includes those blank lines, so I just removed it and left the or{{}{}} block in there.
  4. Extract the item before the : on each line, and extract the domain from that.
  5. Mash it all up into the list.

I don't profess this to be exactly what you need, but it shows how the lists can be parsed and grep'd.

CentOS58[root@ivwm41 exim]# more
# ignore this line

CentOS58[root@ivwm41 exim]# exim -be '${reduce {<; ${readfile{/etc/exim/}{;}} } {} {${if  or{ {match{$item}{#}} {match{$item}{#}} } {$value} {$value:${sg {${extract{1}{:}{$item}}} {^.*@}{} }}}}}'

If you spread out the expansion logically into its individual parts, it looks like this:

exim -be '${reduce {<; ${readfile{/etc/exim/}{;}} } 
             {${if or{ {match{$item}{#}} {match{$item}{#}} } 
                 {$value:${sg{${extract{1}{:}{$item}}} {^.*@} {}}}}

One thing that still needs to be fixed is that leading : should not be there. I'm not 100% sure why it is there :-/ and I don't really have the time to delve any further into it. The logic needs to be massaged a bit to catch whatever condition is causing that leading colon to appear and then the result should be a domain list that you can use as a condition.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.