[Freeswitch-users] Trying to get short hostname

Antony Stone Antony.Stone at freeswitch.open.source.it
Thu Oct 28 19:08:10 UTC 2021


On Thursday 28 October 2021 at 17:29:22, Avi Marcus wrote:

> System doesn't listen to stdout, it's only for running the command.

Er, sorry?

https://freeswitch.org/confluence/display/FREESWITCH/mod_dptools:+system

And anyway, what's wrong with my regex?


Antony.

> On Thu, Oct 28, 2021, 6:22 PM Antony Stone wrote:
> > Hi.
> > 
> > I'm using FreeSwitch 1.10.7 as a client registering to other PBXs as well
> > as a SIP server itself.
> > 
> > I am setting the user-agent string in the SIP profile, such as:
> > 
> > <param name="user-agent-string" value="FS $${CFGver} $${hostname}"/>
> > 
> > The variable $${CFGver}} is a version string I'm definiing in vars.xml
> > 
> > This is working, but it gives me the FQDN of the machine as $${hostname}}
> > and I really only want the machine name without the domain.
> > 
> > I've found
> > https://freeswitch.org/confluence/display/FREESWITCH/Regular+Expression
> > and
> > https://freeswitch.org/confluence/display/FREESWITCH/mod_dptools:+regex
> > and I've tried to use them to cut the domain off the value of $${hostname}
> > but with no success:
> > 
> > In vars.xml:
> > <X-PRE-PROCESS cmd="set"
> > data="shorthostname=${regex($${hostname}|([^\.]*).*|
> > %1)}"/>
> > 
> > This results in the variable shorthostname being assigned the value:
> >         %{regex(abcd.efgh.tld|([^\.]*).*|%1)}
> > 
> > where abcd.efgh.tld is the server's FQDN.
> > 
> > Instead of doing that in vars.xml and creating the variable
> > shorthostname, I tried putting the regex into the SIP profile:
> > 
> > <param name="user-agent-string" value="FS $${CFGver}
> > ${regex($${hostname}| ([^\.]*).*|%1)}"/>
> > 
> > This ends up with precisely the same result.  The ${regex(....)} function
> > simply isn't being executed.
> > 
> > 
> > Given that the machine's hostname is also available from the system
> > command "hostname -s" I decided to try that instead:
> > 
> > In vars.xml:
> > <X-PRE-PROCESS cmd="set" data="shorthostname=${system(hostname -s)}"/>
> > 
> > Or in the SIP profile definition:
> > <param name="user-agent-string" value="FS $${CFGver} ${system(hostname
> > -s)}"/>
> > 
> > These both produce the output:
> >         FS 0.65 ${system(hostname -s)}
> > 
> > In other words, the ${system(....)} command isn't working any more than
> > ${regex(....)} did.
> > 
> > 
> > What am I doing wrong please?
> > 
> > 
> > How can I get the machine's short hostname into a user-agent string for
> > registration to a server?
> > 
> > 
> > Thanks,
> > 
> > 
> > Antony.

-- 
My life is going completely according to plan.

I do sometimes wish it had been *my* plan, though.

                                                   Please reply to the list;
                                                         please *don't* CC me.



More information about the FreeSWITCH-users mailing list