I am looking for help writing a *nix shell script, specifically to execute on OpenWRT environments.
The summary of the process is as follows:
1) The script would query/resolve a DNS (i.e: foobar.example.com) and get the IP address. If multiple IP's are returned, just the first one should be good enough.
>nslookup foobar.example.com 188.8.131.52
Address 1: 184.108.40.206 google-public-dns-a.google.com
Address 1: 220.127.116.11 n003-000-000-000.static.ge.com
Address 2: 18.104.22.168
2) the script would then overwrite a config file with the new resolved IP. Config file: server.conf
foo = bar
bar = foo
some_other_config = 1
server_ip = 22.214.171.124
more_config = true
it should find the line which says server_ip = x.x.x.x, and replce it it server_ip = 126.96.36.199
3) Optionally - it would be nice if we could read the exiting server.conf file and make sure the IP is indeed different and needs to be updated. If yes, then go ahead with the replacement, if not, leave the server.conf alone.
I know this can be achieved by the use of sed and/or awk, but I've had my share of issues doing it, as this is a new area for me.
Any help would be much appreciated.