Append a prefix to computername based on group membership
-
I’m trying to figure out how to expand on the computer naming task while imaging.
I have a group called TestGroup. Let’s say this group is a department in my organization, and the department code is TG. The way we name our computers is DeptCode-serialnumber. So TG-1A2B3CD would be how we name a computer. In FOG, I create the group and see the option to join a domain. Great! However, I want to be able to add the prefix to the computer name BEFORE joining the domain. I already have a script in place during Full Reg that reads the system’s serial number from the BIOS and auto-populates it.
How can I tie that Full Reg script into Groups so that it will either automatically append the prefix or prompt me during Full Reg to specify a department code that is referenced in the Group?
-
@brakcounty OK I have two ideas here.
First method low tech:
At a previous job we would image computers for deployment across the country and the numbering scheme was similar to your SiteLUN code plus serial number. We had a laminated sheet of paper that had a barcode with the site lun code (i.e. USNYC) and human readable text next to it. When we were registering the computers we would plug a usb barcode reader into the target machine. Then when the full registration asked for the computer name, we would zap the destination LUN code then the serial number on the dell asset tag. We could use the FOG standard full registration code since nothing inside fog would have changed.Second method:
I can remember for sure, but I think you are using a version of this script to create the default system name: https://forums.fogproject.org/topic/14278/creating-custom-hostname-default-for-fog-man-reg?_=1675820625786You could prompt in the fog.customhostname script for a department name and then let the script concatenate the entered department name with the collected system serial number.
-
@george1421 I say method#2 works best. Which script should I modify and where? At the beginning or end? Would it work like “read bios serial# prompt for dept code” or “prompt for dept code read bios sn append prefix”?
-
@brakcounty If you look at the fog.man.reg script. How this works.
if [[ -f "/bin/fog.customhostname" ]]; then . /bin/fog.customhostname fi
Calls the script fog.customhostname The calculated name is returned in the variable
$host_default_name
So if you don’t modify the value (over ride the calculated value the calculated value will be passed on to the registration.
So if you look at a bit broader view of the script
if [[ -f "/bin/fog.customhostname" ]]; then . /bin/fog.customhostname fi while [[ $res != "#!ok" ]]; do if [[ $host_default_name != "" ]]; then read -p " * Enter hostname for this computer [$host_default_name]: " host else read -p " * Enter hostname for this computer: " host fi host=${host:-$host_default_name}
If you inserted a prompt to enter a department lun code like this
if [[ -f "/bin/fog.customhostname" ]]; then . /bin/fog.customhostname fi read -p " * Enter destination department for this computer: " dname host_default_name="${dname}-${host_default_name}"; while [[ $res != "#!ok" ]]; do if [[ $host_default_name != "" ]]; then read -p " * Enter hostname for this computer [$host_default_name]: " host else read -p " * Enter hostname for this computer: " host fi host=${host:-$host_default_name}
That should do it. NOW YOU MUST UNDERSTAND, I put almost zero thought into this so I did not test it for syntax correctness. Will it work or not? Testing will tell you. In theory it should work by YMMV.
-
@george1421 You sir, are the man. I added those two lines
read -p " * Enter destination department for this computer: " dname host_default_name="${dname}-${host_default_name}";
to fog.man.reg and was prompted for a department code, entered the dept code, then the hostname autopopped with the dept code prefix appended. However, after the device is registered, the prefix is not appended to the registered name.
-
If I leave the hostname field blank during full reg, where it shows that the prefix is appended and the host name is autopopped, the MAC address becomes the registered hostname. Please note the “t Specified” hostname comes from the firmware of my Virtualbox VM.
-
@brakcounty So just to be clear you have a problem or no problem? The way the hostname works now is that the suggested name is in the square braces. If you press enter there then it should use that as the host name.
This bit of the code then assigns the fog “real” host variable to the constructed name
host=${host:-$host_default_name} if [[ ${#host} -gt 15 ]]; then host=${host:0:15} echo " | Truncated to 15 characters: $host" usleep 2000000 fi
So when the script prints on the screen “Truncated to 15 characters: $host” That host value is printing correctly on the screen. It looks like its working as designed.
NOW one thing I would do is remove any white spaces that happen to creep into the hostname. With something like this
host_default_name=${${host_default_name}-//[[:blank:]]/};
-
@brakcounty said in Append a prefix to computername based on group membership:
However, after the device is registered, the prefix is not appended to the registered name.
Its possible that the space in the name (because of the VM) caused this error.
-
@george1421 I tried entering a hostname after the prefix was appended, for example I entered “TestVM” thinking the full registered hostname would be “NCIT-TestVM”, but the device was registered as “TestVM”.