Resolve netbios-name and pass it to mount.cifs in script

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












I have a script that mounts all the shares from my Windows computer. It's basically:



mount.cifs //192.168.0.7/pictures ~/otherpc/pictures -o user=me,domain=mynetwork,password=12345,vers=3.0


..for about 10 lines.



Problem is, my network is DHCP. So every now and then I have to go change the IP in this script.



The script used to work this way:



mount.cifs //OTHERPC/pictures ~/otherpc/pictures -o user=me,domain=mynetwork,password=12345,ver=3.0


But at some point it started producing the error:



mount error: could not resolve address for OTHERPC: Unknown error


Nautilus resolves the name without a problem, though.



Is there a way to resolve the IP, store it in a variable and then use mount.cifs with //$variable instead of the IP directly in the script?



Thank you










share|improve this question



























    up vote
    3
    down vote

    favorite












    I have a script that mounts all the shares from my Windows computer. It's basically:



    mount.cifs //192.168.0.7/pictures ~/otherpc/pictures -o user=me,domain=mynetwork,password=12345,vers=3.0


    ..for about 10 lines.



    Problem is, my network is DHCP. So every now and then I have to go change the IP in this script.



    The script used to work this way:



    mount.cifs //OTHERPC/pictures ~/otherpc/pictures -o user=me,domain=mynetwork,password=12345,ver=3.0


    But at some point it started producing the error:



    mount error: could not resolve address for OTHERPC: Unknown error


    Nautilus resolves the name without a problem, though.



    Is there a way to resolve the IP, store it in a variable and then use mount.cifs with //$variable instead of the IP directly in the script?



    Thank you










    share|improve this question

























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      I have a script that mounts all the shares from my Windows computer. It's basically:



      mount.cifs //192.168.0.7/pictures ~/otherpc/pictures -o user=me,domain=mynetwork,password=12345,vers=3.0


      ..for about 10 lines.



      Problem is, my network is DHCP. So every now and then I have to go change the IP in this script.



      The script used to work this way:



      mount.cifs //OTHERPC/pictures ~/otherpc/pictures -o user=me,domain=mynetwork,password=12345,ver=3.0


      But at some point it started producing the error:



      mount error: could not resolve address for OTHERPC: Unknown error


      Nautilus resolves the name without a problem, though.



      Is there a way to resolve the IP, store it in a variable and then use mount.cifs with //$variable instead of the IP directly in the script?



      Thank you










      share|improve this question















      I have a script that mounts all the shares from my Windows computer. It's basically:



      mount.cifs //192.168.0.7/pictures ~/otherpc/pictures -o user=me,domain=mynetwork,password=12345,vers=3.0


      ..for about 10 lines.



      Problem is, my network is DHCP. So every now and then I have to go change the IP in this script.



      The script used to work this way:



      mount.cifs //OTHERPC/pictures ~/otherpc/pictures -o user=me,domain=mynetwork,password=12345,ver=3.0


      But at some point it started producing the error:



      mount error: could not resolve address for OTHERPC: Unknown error


      Nautilus resolves the name without a problem, though.



      Is there a way to resolve the IP, store it in a variable and then use mount.cifs with //$variable instead of the IP directly in the script?



      Thank you







      shell-script scripting samba






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 18 '17 at 15:05

























      asked Apr 18 '17 at 4:16









      user659632

      162




      162




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          I see two options you should try before fiddling around with storing the IP in a variable. (Besides, unless the servers already have a hostname, how will you figure out the new IP?)




          • Try mounting with hostname instead of IP, if it is a dynamic IP.



            mount.cifs //cifs.server.com/pictures ~/otherpc/pictures -o user=me,domain=mynetwork,password=12345,vers=3.0


          • If the network is under your control, make DHCP reservations for the IP of the cifs servers.





          share|improve this answer




















          • This might have been useful information in my post, the script used to be like you described in your first option. mount.cifs //otherpc/pictures and so on and it worked fine. But at some point, the script started giving the error "mount error: could not resolve address for OTHERPC: Unknown error." That's why I changed it to the IP. Nautilus can resolve the netbios name without a problem, though.
            – user659632
            Apr 18 '17 at 15:00


















          up vote
          0
          down vote













          I had exactly the same problem after an do-release-upgrade to Ubuntu 18.04.1 LTS. All shares that mounted happily before ended with this ugly



          mount error: could not resolve address for server.domain.local: Unknown error


          nslookup was resolving correctly, syslog and strace did not show anything.



          In the end, the problem was the .local domain together with a change (possibly during the release upgrade) in the /etc/nsswitch.conf witch put the mDNS Avahi/Bonjour daemon mdns4_minimal before dns lookup.



          So the problem was solved after I changed the order from



          hosts: files mdns4_minimal [NOTFOUND=return] resolve [!UNAVAIL=return] dns 


          to



          hosts: files dns mdns4_minimal [NOTFOUND=return] resolve [!UNAVAIL=return]


          I can't remember all helpfull links, but this one certainly did the trick: https://askubuntu.com/a/853284/810573






          share|improve this answer




















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f359594%2fresolve-netbios-name-and-pass-it-to-mount-cifs-in-script%23new-answer', 'question_page');

            );

            Post as a guest






























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            I see two options you should try before fiddling around with storing the IP in a variable. (Besides, unless the servers already have a hostname, how will you figure out the new IP?)




            • Try mounting with hostname instead of IP, if it is a dynamic IP.



              mount.cifs //cifs.server.com/pictures ~/otherpc/pictures -o user=me,domain=mynetwork,password=12345,vers=3.0


            • If the network is under your control, make DHCP reservations for the IP of the cifs servers.





            share|improve this answer




















            • This might have been useful information in my post, the script used to be like you described in your first option. mount.cifs //otherpc/pictures and so on and it worked fine. But at some point, the script started giving the error "mount error: could not resolve address for OTHERPC: Unknown error." That's why I changed it to the IP. Nautilus can resolve the netbios name without a problem, though.
              – user659632
              Apr 18 '17 at 15:00















            up vote
            0
            down vote













            I see two options you should try before fiddling around with storing the IP in a variable. (Besides, unless the servers already have a hostname, how will you figure out the new IP?)




            • Try mounting with hostname instead of IP, if it is a dynamic IP.



              mount.cifs //cifs.server.com/pictures ~/otherpc/pictures -o user=me,domain=mynetwork,password=12345,vers=3.0


            • If the network is under your control, make DHCP reservations for the IP of the cifs servers.





            share|improve this answer




















            • This might have been useful information in my post, the script used to be like you described in your first option. mount.cifs //otherpc/pictures and so on and it worked fine. But at some point, the script started giving the error "mount error: could not resolve address for OTHERPC: Unknown error." That's why I changed it to the IP. Nautilus can resolve the netbios name without a problem, though.
              – user659632
              Apr 18 '17 at 15:00













            up vote
            0
            down vote










            up vote
            0
            down vote









            I see two options you should try before fiddling around with storing the IP in a variable. (Besides, unless the servers already have a hostname, how will you figure out the new IP?)




            • Try mounting with hostname instead of IP, if it is a dynamic IP.



              mount.cifs //cifs.server.com/pictures ~/otherpc/pictures -o user=me,domain=mynetwork,password=12345,vers=3.0


            • If the network is under your control, make DHCP reservations for the IP of the cifs servers.





            share|improve this answer












            I see two options you should try before fiddling around with storing the IP in a variable. (Besides, unless the servers already have a hostname, how will you figure out the new IP?)




            • Try mounting with hostname instead of IP, if it is a dynamic IP.



              mount.cifs //cifs.server.com/pictures ~/otherpc/pictures -o user=me,domain=mynetwork,password=12345,vers=3.0


            • If the network is under your control, make DHCP reservations for the IP of the cifs servers.






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Apr 18 '17 at 7:28









            Rabban

            693210




            693210











            • This might have been useful information in my post, the script used to be like you described in your first option. mount.cifs //otherpc/pictures and so on and it worked fine. But at some point, the script started giving the error "mount error: could not resolve address for OTHERPC: Unknown error." That's why I changed it to the IP. Nautilus can resolve the netbios name without a problem, though.
              – user659632
              Apr 18 '17 at 15:00

















            • This might have been useful information in my post, the script used to be like you described in your first option. mount.cifs //otherpc/pictures and so on and it worked fine. But at some point, the script started giving the error "mount error: could not resolve address for OTHERPC: Unknown error." That's why I changed it to the IP. Nautilus can resolve the netbios name without a problem, though.
              – user659632
              Apr 18 '17 at 15:00
















            This might have been useful information in my post, the script used to be like you described in your first option. mount.cifs //otherpc/pictures and so on and it worked fine. But at some point, the script started giving the error "mount error: could not resolve address for OTHERPC: Unknown error." That's why I changed it to the IP. Nautilus can resolve the netbios name without a problem, though.
            – user659632
            Apr 18 '17 at 15:00





            This might have been useful information in my post, the script used to be like you described in your first option. mount.cifs //otherpc/pictures and so on and it worked fine. But at some point, the script started giving the error "mount error: could not resolve address for OTHERPC: Unknown error." That's why I changed it to the IP. Nautilus can resolve the netbios name without a problem, though.
            – user659632
            Apr 18 '17 at 15:00













            up vote
            0
            down vote













            I had exactly the same problem after an do-release-upgrade to Ubuntu 18.04.1 LTS. All shares that mounted happily before ended with this ugly



            mount error: could not resolve address for server.domain.local: Unknown error


            nslookup was resolving correctly, syslog and strace did not show anything.



            In the end, the problem was the .local domain together with a change (possibly during the release upgrade) in the /etc/nsswitch.conf witch put the mDNS Avahi/Bonjour daemon mdns4_minimal before dns lookup.



            So the problem was solved after I changed the order from



            hosts: files mdns4_minimal [NOTFOUND=return] resolve [!UNAVAIL=return] dns 


            to



            hosts: files dns mdns4_minimal [NOTFOUND=return] resolve [!UNAVAIL=return]


            I can't remember all helpfull links, but this one certainly did the trick: https://askubuntu.com/a/853284/810573






            share|improve this answer
























              up vote
              0
              down vote













              I had exactly the same problem after an do-release-upgrade to Ubuntu 18.04.1 LTS. All shares that mounted happily before ended with this ugly



              mount error: could not resolve address for server.domain.local: Unknown error


              nslookup was resolving correctly, syslog and strace did not show anything.



              In the end, the problem was the .local domain together with a change (possibly during the release upgrade) in the /etc/nsswitch.conf witch put the mDNS Avahi/Bonjour daemon mdns4_minimal before dns lookup.



              So the problem was solved after I changed the order from



              hosts: files mdns4_minimal [NOTFOUND=return] resolve [!UNAVAIL=return] dns 


              to



              hosts: files dns mdns4_minimal [NOTFOUND=return] resolve [!UNAVAIL=return]


              I can't remember all helpfull links, but this one certainly did the trick: https://askubuntu.com/a/853284/810573






              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                I had exactly the same problem after an do-release-upgrade to Ubuntu 18.04.1 LTS. All shares that mounted happily before ended with this ugly



                mount error: could not resolve address for server.domain.local: Unknown error


                nslookup was resolving correctly, syslog and strace did not show anything.



                In the end, the problem was the .local domain together with a change (possibly during the release upgrade) in the /etc/nsswitch.conf witch put the mDNS Avahi/Bonjour daemon mdns4_minimal before dns lookup.



                So the problem was solved after I changed the order from



                hosts: files mdns4_minimal [NOTFOUND=return] resolve [!UNAVAIL=return] dns 


                to



                hosts: files dns mdns4_minimal [NOTFOUND=return] resolve [!UNAVAIL=return]


                I can't remember all helpfull links, but this one certainly did the trick: https://askubuntu.com/a/853284/810573






                share|improve this answer












                I had exactly the same problem after an do-release-upgrade to Ubuntu 18.04.1 LTS. All shares that mounted happily before ended with this ugly



                mount error: could not resolve address for server.domain.local: Unknown error


                nslookup was resolving correctly, syslog and strace did not show anything.



                In the end, the problem was the .local domain together with a change (possibly during the release upgrade) in the /etc/nsswitch.conf witch put the mDNS Avahi/Bonjour daemon mdns4_minimal before dns lookup.



                So the problem was solved after I changed the order from



                hosts: files mdns4_minimal [NOTFOUND=return] resolve [!UNAVAIL=return] dns 


                to



                hosts: files dns mdns4_minimal [NOTFOUND=return] resolve [!UNAVAIL=return]


                I can't remember all helpfull links, but this one certainly did the trick: https://askubuntu.com/a/853284/810573







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Aug 21 at 11:48









                sc911

                1




                1



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f359594%2fresolve-netbios-name-and-pass-it-to-mount-cifs-in-script%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?