Hi all,
Quick question. Is there a way to easily add a prefix to the device name when I add clients to a certain directory? I was thinking about making a profile using a variable in the device name. But I am unsure if this works and which variable to use for this.
Anyone have any experience with this?
Hi Jordy,
does it need to happen automatically or on demand from the endpoint side?
Which prefix should be used and where does it come from?
Automatically when the device is added to a certain directory (so with a profile setting preferably). The prefix would be something like SEH-<Devicename> or IC-<Devicename>.
The variable devicename being the current devicename assigned in UMS. So that would be the Attribute: “Name”.
This is because we need to filter based on Hostname in our Imprivata environment to start pushing different grace periods.
You can do this with a script in a profile attached to that directory. We do it for Imprivata, as well, but rather than adding characters to the hostname, I simply change the first three (to ‘IGS’ in this instance):
#!/bin/bash
RENAMEVAR=$($HOSTNAME | tr -dc ‘[:alnum:]nr’ | tr ‘[:lower:]’ ‘[:upper:]’ | sed ‘s/^/IGS/’)
HOSTNAME=$(hostname)
if [ “$RENAMEVAR” != “$HOSTNAME” ]
then
setparam network.dns.hostname $RENAMEVAR
killall postsetupd
write_rmsettings
fi
You’d need to make sure that the following UMS options are also enabled so that this works:
@member Thanks for replying!! So if i understand correctly, if i use this script and replace IGS in that script with w/e it should add that as a prefix to the Devicename and this will also be the used networkname?
So we use Cxxxxx as our computernames currently. That will then be IGSCxxxxx using this script if i am correct?
Yeah, I wanted to keep using the existing hostname, which is basically ITC plus the MAC address. That script will just change the ITC to IGS.
It’d be easier if you simply wanted to add characters to the beginning:
`RENAMEVAR=NEW$HOSTNAME`
I just didn’t want to deal with a hostname that long. Didn’t make sense to me.
Okay, i am trying to understand the programming which fills the variable renamevar. But basically you say replace the contents of this variable and use RENAMEVAR=<Prefix>$hostname?
So whatever i want can be filled in into the prefix area.
Yep, RENAMEVAR= is basically just the start of creating a new variable named $RENAMEVAR.
It all leads to this, where the new hostname is actually set: setparam network.dns.hostname $RENAMEVAR
Yeah exactly, i was trying to understand which value i could add to the variable, but i will create a profile and test your suggestion. Thanks!!
You should be able to add any value, really. It’s just concatenating everything right there.
Hm i have both options enabled which you stated but it doesn’t work currently. I did enable the 2 checkmarks to change netwerkname which you stated previously.
Did i miss something?
`#!/bin/bash`
`RENAMEVAR=$(4HG$HOSTNAME)`
`HOSTNAME=$(hostname)`
`if [ “$RENAMEVAR” != “$HOSTNAME” ]`
`then`
`setparam network.dns.hostname $RENAMEVAR`
`killall postsetupd`
`write_rmsettings`
`fi`
Try replacing the second line with this:
`RENAMEVAR=4HG$HOSTNAME`
Also, you do need to reboot the device for the changes to take effect.
Yea the reboot made sense 😛. But what i am wondering is i use the line2 suggestion you made. But i want to make a Hyphen en the middle. So now i user RENAMEVAR=4HG-$HOSTNAME.
Right now it will rename the device to 4HG-LOCALHOST.
If you SSH into one of your thin clients, you can test that RENAMEVAR line out without actually making any changes. That way, you know what to expect when you include it in your script/profile.
Thanks for that tip i will check it out.
Looks like the issue with Localhost is that before the connection is built up the hostname variable is not filled and thats why it puts localhost. I am looking for a workaround for this.
Give this a shot:
#!/bin/bash
RENAMEVAR=4HG-$(cat /sys/class/net/eth0/address | tr -dc ‘[:alnum:]nr’ | tr ‘[:lower:]’ ‘[:upper:]’)
HOSTNAME=$(hostname)
if [ “$RENAMEVAR” != “$HOSTNAME” ]
then
setparam network.dns.hostname $RENAMEVAR
killall postsetupd
write_rmsettings
fi
Since the hostnames are by default the MAC, it’s just another way to grab it to create that variable.
Whoops – change line 2 to this:
RENAMEVAR=4HG-ITC$(cat /sys/class/net/eth0/address | tr -dc ‘[:alnum:]nr’ | tr ‘[:lower:]’ ‘[:upper:]’)
Assuming you want to keep the format [NewPrefix]-ITC############
Currently not using ITC<MAC>.
We use Cxxxxx as our format for our computernames.
And we see that te problem is that the hostname will not be configured after the device is connected to the network. But if you do that the device will start looping and it will keep adding the prefix untill infinity haha.
With the old code i used before the network settings.
Ah, sorry then, I assumed you were looking to change from the default name to just adding a prefix.
I think something is wrong with the IF statement. But im going to look into it. I cant get it to run only once which is the only thing i need.
If i have a solution i will share it for future reference.
Continue reading and comment on the thread ‘How to easily add a prefix to the IGEL OS device name when I add clients to a certain directory?’. Not a member? Join Here!
Learn more, search the IGEL Knowledge Base
Ask a question or comment on the above message thread?
Join or log in to the IGEL Community to ask us anything and meet other IGEL customers, partners, and EUC enthusiasts.Submit a question, or Join Today!