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

    Linux FOG Client, Hostname Changer not working

    Scheduled Pinned Locked Moved Solved
    Linux Problems
    hostname change linux client
    3
    13
    1.5k
    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.
    • A
      aknisly @george1421
      last edited by

      @george1421 Thanks very much for this quick and helpful response! A few sentences of explanation can bridge what feels like a wide chasm of knowledge.

      Unfortunately, I’ve not got this working yet. Here is what I’ve done:
      On the server…

      [admin@localhost postdownloadscripts]$ cat fog.postdownload 
      !/bin/bash
      ## This file serves as a starting point to call your custom postimaging scripts.
      ## <SCRIPTNAME> should be changed to the script you're planning to use.
      ## Syntax of post download scripts are
      . ${postdownpath}/fog.sethostname
      
      [admin@localhost postdownloadscripts]$ cat fog.sethostname 
      !/bin/bash
      . /usr/share/fog/lib/funcs.sh
      [[ -z $postdownpath ]] && postdownpath="/images/postdownloadscripts/"
      
      if [ "$osId" == "50" && ! -z $hostname ]; then
           [[ ! -d /ntfs ]] && mkdir -p /ntfs
           mount /dev/sda5 /ntfs
           echo $hostname > /etc/hostname
           sync
           umount /ntfs
      fi
      
      [admin@localhost postdownloadscripts]$ ls -la
      total 8
      drwxrwxrwx.  2 fogproject root  53 Dec  8 10:22 .
      drwxrwxrwx. 10 fogproject root 177 Dec  7 16:52 ..
      -rwxrwxrwx.  1 fogproject root 238 Dec  8 09:54 fog.postdownload
      -rwxrwxrwx.  1 fogproject root 294 Dec  8 10:22 fog.sethostname
      

      (I gave 777 to the fog.sethostname just in case, since fog.postdownload had those permissions.)

      On the host…

      pilgrim@pcsthinlinc:~$ df -h
      Filesystem      Size  Used Avail Use% Mounted on
      udev            1.9G     0  1.9G   0% /dev
      tmpfs           388M  1.5M  386M   1% /run
      /dev/sda5        15G  7.4G  6.0G  56% /
      tmpfs           1.9G     0  1.9G   0% /dev/shm
      tmpfs           5.0M  4.0K  5.0M   1% /run/lock
      tmpfs           1.9G     0  1.9G   0% /sys/fs/cgroup
      /dev/sda1       480M  4.0K  480M   1% /boot/efi
      tmpfs           388M   16K  388M   1% /run/user/1000
      
      

      The image deployed to the host as expected, but as you can see, it didn’t get the ‘LAPTOP-10’ hostname. Does the fact that the server doesn’t list this host as a Linux OS have anything to do with it? I don’t understand why all of our hosts (both Windows and Linux) show the image OS as ‘unknown.’
      Screenshot at 2021-12-08 10-57-47.png
      The ‘Mint Thin Client’ image is correctly registered as Linux:
      Screenshot at 2021-12-08 10-59-23.png

      Are there logs that I can access?
      Thanks again!

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

        @aknisly Fist of all I’m hoping the form just ate your leading pound on the bash files.

        Just for clarity a bash script needs to always start with

        #!/bin/bash
        

        If not, she won’t run.

        Everything else looks good. We might want to add in a few “debugging” echos.

        !/bin/bash
        
        . /usr/share/fog/lib/funcs.sh
        [[ -z $postdownpath ]] && postdownpath="/images/postdownloadscripts/"
        
        Echo Updating target computer to host name [ $hostname ]
        debugPause
        
        if [ "$osId" == "50" && ! -z $hostname ]; then
             [[ ! -d /ntfs ]] && mkdir -p /ntfs
             mount /dev/sda5 /ntfs
             echo $hostname > /etc/hostname
             sync
        
             echo Host name updated on target computer
             debugPause
             umount /ntfs
        fi
        

        That should then print when your scripts starts to run and if the if statement was satisfied it should say host updated.

        Now the last bit is a tip I use when debugging post install scripts. To setup the deploy task but check the debug option. Then pxe boot the target computer. In the debug mode you will be dropped to the FOS Linux command prompt. To start imaging just key in the word fog. This will single step you through the imaging process. Right after the last partclone screen is displayed is when the post install scripts will run. You should see on the screen

        Updating target computer to host name [ $hostname ]
        

        Then because we put a debugPause in right after that echo the script will stop waiting for an enter key press. Ensure the hostname value is being set. If that bit looks OK press enter. Hopefully the next time it stops will be at

        Host name updated on target computer. 
        

        If you have an error or something else press Ctrl-C and exit the imaging program. You will now be able to check to ensure your partition is mapped correctly or what ever happened. You can simply restart deployment by keying in fog again to restart the imaging process in debug mode.

        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!

        A 1 Reply Last reply Reply Quote 0
        • A
          aknisly @george1421
          last edited by

          @george1421 Wow! Whatever they’re paying you, it’s not enough…:-)

          RE: the leading # on the first line: <pounds forehead with open palm> Duh. I knew that. I just mindlessly followed the script as you had posted it.

          I love the debugging magic; that’s a game-changer. All is well up to line 8. I can’t figure out why, but I’m getting

          line 8: [: missing ']'
          

          Sorry for being slow…

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

            @aknisly Just remove the square brackets around the $hostname variable. Its only decoration. I didn’t really debug the script (I should have), but that’s all part of learning (i.e. falling flat on your face and then trying to figure out what happened).

            Know that when you are in debug mode and hit that error in the script you can hit crtl-c to blow out of deployment. Then fix the script on the fog server and rerun fog to start the deployment over again.

            Wow! Whatever they’re paying you, it’s not enough…:-)

            All the cookies and soda I can consume is my pay.

            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!

            A 1 Reply Last reply Reply Quote 0
            • A
              aknisly @george1421
              last edited by aknisly

              @george1421 Done. It took digging deeper into BASH scripting, and thinking through what the script was attempting to do, but it finally worked. Notably, the 2-condition test in the ‘if’ statement was giving me grief until I separated it into two double brackets (two single brackets may have worked?). I know there are a dozen ways of doing this, but this worked for me. Also, the ‘$osId’ needed to be ‘$osid’, and the /etc/hostname needed to be in the mounted directory instead of in the FOS environment.
              For others wanting to use this, here is the complete script as I adapted it to work, with the debugging elements removed.

              #!/bin/bash
              . /usr/share/fog/lib/funcs.sh
              [[ -z $postdownpath ]] && postdownpath="/images/postdownloadscripts/"
              
              if [[ "$osid" == "50" ]] && [[ ! -z $hostname ]]
              then
                   [[ ! -d /imagefs ]] && mkdir -p /imagefs
                   mount /dev/sda5 /imagefs
                   echo $hostname > /imagefs/etc/hostname
                   sync
                   umount /imagefs
              fi
              

              A few more notes for others trying to make something like this work:

              • For anyone else having trouble with scripting, the debugging option is a life-saver. I ended up putting a debugPause (preceded by an “echo” or similar output statement) after every line to narrow my problem down.
              • It took me longer than it should have to figure out the details of the ‘if’ statements in @george1421’s sample script. The -z checks for a null value (in this case for $hostname the “!” is not, so this is saying if the $hostname variable is not null, then… Here is a good guide on these.
                *@george1421 has listed the FOG variables available in FOS (FogOS) here. I didn’t find this in the wiki. In that same thread, he notes a way to get a pile of other variables from the FOG server by running a script.
                *For a short primer on the post-install script concept itself, this post and a few others in that thread were the best I found.

              Again, @george1421, many, many thanks for your prompt, patient help. I’ve just made a donation to the FOG project in your honor.

              If I could have an account for the wiki, I’d be happy to put some of this info together in a tutorial for changing hostname and post-install scripting.

              Who marks this as ‘solved’?

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

                @aknisly Very well done! I realize the path to get here was a bit rough. BUT you have now learned something for the next time you want to adjust something else using a post install script (its that giving a fish vs teaching how to fish, thing).

                As I’ve told others, “If it worked correctly the first time, what would you have learned?” So we applaud you on working through this and then posting your success here.

                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
                • S
                  Sebastian Roth Moderator
                  last edited by

                  @aknisly This just confirms why we don’t get to fix the HostnameChanger module in the fog-client. My post on what to look at in the fog-client was ignored. Nevermind.

                  Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

                  Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

                  A 1 Reply Last reply Reply Quote 0
                  • A
                    aknisly @Sebastian Roth
                    last edited by

                    @sebastian-roth (Belated reply…) Thanks for this helpful explanation. I certainly am not critical of the unfinished work here–what you have already is one incredible work of science/art.
                    I did take a look at the code, and have a rough idea of what is being attempted there. But it’s true that the post-install script is pretty low-hanging fruit once you get your head under the hood. If I hadn’t been able to get what I wanted with that, I’d be happy to help with the fog-client and the HostnameChanger module, but as it is, unfortunately, I’m pressed to move on to other priorities.
                    I would be happy to make some notes in the wiki (which is still the first place I check) if that is an option. Apparently self-registering an account is disabled?
                    I’d also like to mark this topic solved, but can’t figure out how. Can you do that?
                    Again, huge kudos for this project. And 5-stars for responsive devs on the forum!

                    1 Reply Last reply Reply Quote 0
                    • S
                      Sebastian Roth Moderator
                      last edited by

                      @aknisly said in Linux FOG Client, Hostname Changer not working:

                      If I hadn’t been able to get what I wanted with that, I’d be happy to help with the fog-client and the HostnameChanger module, but as it is, unfortunately, I’m pressed to move on to other priorities.

                      Thanks for being open and honest. Good you were not afronted by my last reply.

                      I would be happy to make some notes in the wiki (which is still the first place I check) if that is an option. Apparently self-registering an account is disabled?

                      We work on updating and moving all the contents from the wiki to https://docs.fogproject.org and you are very welcome to help us. Please send me a private message with your github account name and we’ll permit you to the fog-docs repo.

                      Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

                      Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

                      1 Reply Last reply Reply Quote 1
                      • A
                        aknisly @Sebastian Roth
                        last edited by

                        This post is deleted!
                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        • First post
                          Last post

                        220

                        Online

                        12.0k

                        Users

                        17.3k

                        Topics

                        155.2k

                        Posts
                        Copyright © 2012-2024 FOG Project