Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

An example of /etc/exim4/forwards:

a@test.com: a@lala.com
# ignore this line
b@test.com: a@example.com
b@hugo.com: hugo@example.com

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

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

share|improve this question
add comment

1 Answer

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 test_list.cf 
a@test.com: a@lala.com
# ignore this line
b@test.com: a@example.com
b@hugo.com: hugo@example.com

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

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

exim -be '${reduce {<; ${readfile{/etc/exim/test_list.cf}{;}} } 
             {}
             {${if or{ {match{$item}{#}} {match{$item}{#}} } 
                 {$value}
                 {$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
add comment

Your Answer

 
discard

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.