I have some smart script, that check name of server and get domain name. For example, i have name of server: example.ru01. I need to get: example.ru My scipt:
#!/bin/bash
hostname=example.com01
echo $hostname
reg0="\(\(\w*\.[a-z]*\)\|\(\w*\.[a-z]*\.[a-z]*\)\)"
domain=`expr match $hostname $reg0`
echo $domain
It is ok. in output i have:
example.com01
example.com
But, in my infrastructure, i have some domains with hyphens. For example: test-test.com01. But it doesn't working in my script. How to resolve this problem ? Please help. I made some changes in my regular expression, like this:
\(\(\w*\.[a-z_-]*\)\|\(\w*\.[a-z_-]*\.[a-z_-]*\)\)
But it doesn't work. Where i have error ? Please help. Thanks for your attention.