This bash script is checking if smtp entry is defined in /etc/hosts in docker container:
file: check_hosts_entry
#!/usr/bin/env bash
smtp=$(docker exec -t app bash -c "cat /etc/hosts | grep -m 1 your_smtp_domain" | tr -d '\r');
if [[ "$smtp" != "your.ip your_smtp_domain" ]]; then
echo 'No SMTP entry. Adding it...';
docker exec -t app bash -c "echo your.ip your_smtp_domain >> /etc/hosts";
else
echo 'The SMTP entry is already there!';
fi
crontab
Add it to your host’s crontab to be run every 30 mins or whatever you like:
*/30 * * * * /root/bin/check_hosts_entry >/tmp/stdout.log 2>/tmp/stderr.log
*Don’t forget to replace your.ip and your_smtp_domain with your specific data ![]()