fstab mounting time

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





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
1
down vote

favorite












I'm working on a script that is supposed to execute on startup, but the problem is that the script requires some files that are on a shared drive that is automatically mounted via fstab and at the time of it's execution the drive isn't mounted yet.



I've tried using cron @reboot and init.d route but they both execute too early. I also considered adding mount -a to the script, but I would rather avoid having to sudo it. For now I just added a delay to make it work, but that feels a bit hacky.



Is there a way to ensure that a startup script runs after fstab has been processed? Or force the mounts to be processed without using sudo?







share|improve this question



















  • You are using Ubuntu, an operating system that has been a systemd operating system since 2016 and was an Upstart operating system for a decade before that, since 2006. van Smoorenburg rc scripts have not been a "route" for a long time on your operating system. The systemd version of this question has already been asked and answered here at unix.stackexchange.com/questions/246935 .
    – JdeBP
    Jul 19 at 15:38

















up vote
1
down vote

favorite












I'm working on a script that is supposed to execute on startup, but the problem is that the script requires some files that are on a shared drive that is automatically mounted via fstab and at the time of it's execution the drive isn't mounted yet.



I've tried using cron @reboot and init.d route but they both execute too early. I also considered adding mount -a to the script, but I would rather avoid having to sudo it. For now I just added a delay to make it work, but that feels a bit hacky.



Is there a way to ensure that a startup script runs after fstab has been processed? Or force the mounts to be processed without using sudo?







share|improve this question



















  • You are using Ubuntu, an operating system that has been a systemd operating system since 2016 and was an Upstart operating system for a decade before that, since 2006. van Smoorenburg rc scripts have not been a "route" for a long time on your operating system. The systemd version of this question has already been asked and answered here at unix.stackexchange.com/questions/246935 .
    – JdeBP
    Jul 19 at 15:38













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I'm working on a script that is supposed to execute on startup, but the problem is that the script requires some files that are on a shared drive that is automatically mounted via fstab and at the time of it's execution the drive isn't mounted yet.



I've tried using cron @reboot and init.d route but they both execute too early. I also considered adding mount -a to the script, but I would rather avoid having to sudo it. For now I just added a delay to make it work, but that feels a bit hacky.



Is there a way to ensure that a startup script runs after fstab has been processed? Or force the mounts to be processed without using sudo?







share|improve this question











I'm working on a script that is supposed to execute on startup, but the problem is that the script requires some files that are on a shared drive that is automatically mounted via fstab and at the time of it's execution the drive isn't mounted yet.



I've tried using cron @reboot and init.d route but they both execute too early. I also considered adding mount -a to the script, but I would rather avoid having to sudo it. For now I just added a delay to make it work, but that feels a bit hacky.



Is there a way to ensure that a startup script runs after fstab has been processed? Or force the mounts to be processed without using sudo?









share|improve this question










share|improve this question




share|improve this question









asked Jul 19 at 15:29









Maxim

21715




21715











  • You are using Ubuntu, an operating system that has been a systemd operating system since 2016 and was an Upstart operating system for a decade before that, since 2006. van Smoorenburg rc scripts have not been a "route" for a long time on your operating system. The systemd version of this question has already been asked and answered here at unix.stackexchange.com/questions/246935 .
    – JdeBP
    Jul 19 at 15:38

















  • You are using Ubuntu, an operating system that has been a systemd operating system since 2016 and was an Upstart operating system for a decade before that, since 2006. van Smoorenburg rc scripts have not been a "route" for a long time on your operating system. The systemd version of this question has already been asked and answered here at unix.stackexchange.com/questions/246935 .
    – JdeBP
    Jul 19 at 15:38
















You are using Ubuntu, an operating system that has been a systemd operating system since 2016 and was an Upstart operating system for a decade before that, since 2006. van Smoorenburg rc scripts have not been a "route" for a long time on your operating system. The systemd version of this question has already been asked and answered here at unix.stackexchange.com/questions/246935 .
– JdeBP
Jul 19 at 15:38





You are using Ubuntu, an operating system that has been a systemd operating system since 2016 and was an Upstart operating system for a decade before that, since 2006. van Smoorenburg rc scripts have not been a "route" for a long time on your operating system. The systemd version of this question has already been asked and answered here at unix.stackexchange.com/questions/246935 .
– JdeBP
Jul 19 at 15:38











2 Answers
2






active

oldest

votes

















up vote
2
down vote



accepted










For that you have to run your script as a systemd unit (assuming you have systemd) where you could define dependency...



If you want to stick with cron @reboot (what sounds the simple choice) you have to make your script a bit smarter (or start cron after fs mounts... what change I wouldn't suggest). Instead of a simple delay, you can check if the required filesystem is mounted (in bash):



while ! mount | awk 'print $3' | grep -qx /the/mountpoint; do
sleep 1
done


Or you can check if the file is there what you need:



while ! [ -f /that/file ] ; do
sleep 1
done





share|improve this answer




























    up vote
    0
    down vote













    I'm going to assume you're on a relatively new Linux distro, so you may need to check systemd manual since SysV is no longer being used in the default distro installations and that is most probably your problem. systemd allows for startup dependencies where you specify what scripts run before others.



    Check the next link






    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%2f457247%2ffstab-mounting-time%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
      2
      down vote



      accepted










      For that you have to run your script as a systemd unit (assuming you have systemd) where you could define dependency...



      If you want to stick with cron @reboot (what sounds the simple choice) you have to make your script a bit smarter (or start cron after fs mounts... what change I wouldn't suggest). Instead of a simple delay, you can check if the required filesystem is mounted (in bash):



      while ! mount | awk 'print $3' | grep -qx /the/mountpoint; do
      sleep 1
      done


      Or you can check if the file is there what you need:



      while ! [ -f /that/file ] ; do
      sleep 1
      done





      share|improve this answer

























        up vote
        2
        down vote



        accepted










        For that you have to run your script as a systemd unit (assuming you have systemd) where you could define dependency...



        If you want to stick with cron @reboot (what sounds the simple choice) you have to make your script a bit smarter (or start cron after fs mounts... what change I wouldn't suggest). Instead of a simple delay, you can check if the required filesystem is mounted (in bash):



        while ! mount | awk 'print $3' | grep -qx /the/mountpoint; do
        sleep 1
        done


        Or you can check if the file is there what you need:



        while ! [ -f /that/file ] ; do
        sleep 1
        done





        share|improve this answer























          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          For that you have to run your script as a systemd unit (assuming you have systemd) where you could define dependency...



          If you want to stick with cron @reboot (what sounds the simple choice) you have to make your script a bit smarter (or start cron after fs mounts... what change I wouldn't suggest). Instead of a simple delay, you can check if the required filesystem is mounted (in bash):



          while ! mount | awk 'print $3' | grep -qx /the/mountpoint; do
          sleep 1
          done


          Or you can check if the file is there what you need:



          while ! [ -f /that/file ] ; do
          sleep 1
          done





          share|improve this answer













          For that you have to run your script as a systemd unit (assuming you have systemd) where you could define dependency...



          If you want to stick with cron @reboot (what sounds the simple choice) you have to make your script a bit smarter (or start cron after fs mounts... what change I wouldn't suggest). Instead of a simple delay, you can check if the required filesystem is mounted (in bash):



          while ! mount | awk 'print $3' | grep -qx /the/mountpoint; do
          sleep 1
          done


          Or you can check if the file is there what you need:



          while ! [ -f /that/file ] ; do
          sleep 1
          done






          share|improve this answer













          share|improve this answer



          share|improve this answer











          answered Jul 19 at 15:43









          redseven

          1876




          1876






















              up vote
              0
              down vote













              I'm going to assume you're on a relatively new Linux distro, so you may need to check systemd manual since SysV is no longer being used in the default distro installations and that is most probably your problem. systemd allows for startup dependencies where you specify what scripts run before others.



              Check the next link






              share|improve this answer

























                up vote
                0
                down vote













                I'm going to assume you're on a relatively new Linux distro, so you may need to check systemd manual since SysV is no longer being used in the default distro installations and that is most probably your problem. systemd allows for startup dependencies where you specify what scripts run before others.



                Check the next link






                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  I'm going to assume you're on a relatively new Linux distro, so you may need to check systemd manual since SysV is no longer being used in the default distro installations and that is most probably your problem. systemd allows for startup dependencies where you specify what scripts run before others.



                  Check the next link






                  share|improve this answer













                  I'm going to assume you're on a relatively new Linux distro, so you may need to check systemd manual since SysV is no longer being used in the default distro installations and that is most probably your problem. systemd allows for startup dependencies where you specify what scripts run before others.



                  Check the next link







                  share|improve this answer













                  share|improve this answer



                  share|improve this answer











                  answered Jul 19 at 15:39









                  YoMismo

                  2,8831619




                  2,8831619






















                       

                      draft saved


                      draft discarded


























                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f457247%2ffstab-mounting-time%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?

                      Bahrain

                      Postfix configuration issue with fips on centos 7; mailgun relay