[TUTORIAL] Sync PMG Domains with file from external source

coolcat1975

Renowned Member
Mar 18, 2013
26
2
68
Falls es wer brauchen kann

Bash:
#!/bin/bash
rm delete.txt create.txt existingdomainsraw.txt existingdomainspmg.txt
pmgsh get /config/domains/ | grep domain | cut -d ":" -f 2 | awk '{print substr($0,3,length($0)-3)}' > existingdomainsraw.txt && tail -n +1 existingdomainsraw.txt > existingdomainspmg.txt
#müssen angelegt werden
diff --left-column --changed-group-format="%>" --unchanged-group-format="" existingdomainspmg.txt existingdomainsexternalsource.txt > create.txt
#müssen gelöscht werden
diff --left-column --changed-group-format="%>" --unchanged-group-format="" existingdomainsexternalsource.txt existingdomainspmg.txt > delete.txt
while read i ; do pmgsh create /config/domains/ --comment "create" --domain $i ; done < create.txt
while read i ; do pmgsh delete /config/domains/$i ; done < delete.txt
 
  • Like
Reactions: Stoiko Ivanov
Danke fürs Teilen des Scripts - wird bestimmt auch Anderen helfen!

Als winziger Tipp (da ich es erst gelernt habe): shellcheck ist ein recht netter linter für shellscript - hat mir schon oft geholfen scripte noch ein wenig robuster zu machen.

P.S. Ich habe den Thread mal mit dem 'TUTORIAL' prefix versehen - das sollte bei der Suche auch nochmal helfen
 
Hi,
How to modify this so I can sync PMG with my WHM/Cpanel domain list? I don't understand how to use that code.
 
Hi!

Actually there is no modification needed. You need to export the list of domains from WHM/Cpanel into a textfile named existingdomainsexternalsource.txt and copy this file from your WHM/Cpanel installation to the PMG into the same directory where the script resides.

How to generate the list of existing domains on any source mailsystem is out of scope of this howto.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!