• Recent
    • Unsolved
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Append a prefix to computername based on group membership

    General
    2
    9
    145
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      brakcounty
      last edited by

      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?

      george1421G 1 Reply Last reply Reply Quote 0
      • B
        brakcounty
        last edited by

        @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”.

        1 Reply Last reply Reply Quote 0
        • george1421G
          george1421 Moderator @brakcounty
          last edited by

          @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.

          Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!

          1 Reply Last reply Reply Quote 0
          • george1421G
            george1421 Moderator @brakcounty
            last edited by

            @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:]]/};
            

            Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!

            1 Reply Last reply Reply Quote 0
            • B
              brakcounty
              last edited by brakcounty

              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.

              6e4047d2-c374-468f-9eea-fb91e81fedd3-image.png

              george1421G 1 Reply Last reply Reply Quote 0
              • B
                brakcounty @george1421
                last edited by brakcounty

                @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.

                george1421G 1 Reply Last reply Reply Quote 0
                • george1421G
                  george1421 Moderator @brakcounty
                  last edited by

                  @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.

                  Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!

                  B 1 Reply Last reply Reply Quote 1
                  • B
                    brakcounty @george1421
                    last edited by

                    @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”?

                    george1421G 1 Reply Last reply Reply Quote 0
                    • george1421G
                      george1421 Moderator @brakcounty
                      last edited by

                      @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?_=1675820625786

                      You 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.

                      Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!

                      B 1 Reply Last reply Reply Quote 2
                      • 1 / 1
                      • First post
                        Last post

                      147

                      Online

                      10.6k

                      Users

                      16.5k

                      Topics

                      151.1k

                      Posts
                      Copyright © 2012-2023 FOG Project