How to run a .sh file in terminal on login












1















so I have a simple sh file I want to run whenever someone logs in. I tried adding it to startup applications. This didn't work. I tried editing the .desktop file for the startup application to set Terminal=true. This made it open temporarily but shut it down.
I tried editing .bashrc by adding the command bash /path/to/my/file.sh and it had the same effect. This seems like it should be really simple to do, even in linux, but I have tried lots of ways and had no success. I am on Ubuntu 14.something.










share|improve this question


















  • 1





    All of those methods should have worked (well, the .bashrc one is only on opening a Terminal; .profile would have been better). What are you doing inside the .sh file? Is the executable bit set? Does it start with #!/bin/bash?

    – saiarcot895
    Jul 3 '14 at 16:41













  • As @saiarcot895 you may forgot to give executable permissions to file.

    – Sudheer
    Jul 3 '14 at 16:43











  • You would be able to find out what filetype it is set to by typing in ls -la

    – ryekayo
    Jul 3 '14 at 16:49











  • Please edit your post and include the script in question. Also, please clarify if you want this to run for a single user or for all users.

    – terdon
    Jul 3 '14 at 16:53
















1















so I have a simple sh file I want to run whenever someone logs in. I tried adding it to startup applications. This didn't work. I tried editing the .desktop file for the startup application to set Terminal=true. This made it open temporarily but shut it down.
I tried editing .bashrc by adding the command bash /path/to/my/file.sh and it had the same effect. This seems like it should be really simple to do, even in linux, but I have tried lots of ways and had no success. I am on Ubuntu 14.something.










share|improve this question


















  • 1





    All of those methods should have worked (well, the .bashrc one is only on opening a Terminal; .profile would have been better). What are you doing inside the .sh file? Is the executable bit set? Does it start with #!/bin/bash?

    – saiarcot895
    Jul 3 '14 at 16:41













  • As @saiarcot895 you may forgot to give executable permissions to file.

    – Sudheer
    Jul 3 '14 at 16:43











  • You would be able to find out what filetype it is set to by typing in ls -la

    – ryekayo
    Jul 3 '14 at 16:49











  • Please edit your post and include the script in question. Also, please clarify if you want this to run for a single user or for all users.

    – terdon
    Jul 3 '14 at 16:53














1












1








1








so I have a simple sh file I want to run whenever someone logs in. I tried adding it to startup applications. This didn't work. I tried editing the .desktop file for the startup application to set Terminal=true. This made it open temporarily but shut it down.
I tried editing .bashrc by adding the command bash /path/to/my/file.sh and it had the same effect. This seems like it should be really simple to do, even in linux, but I have tried lots of ways and had no success. I am on Ubuntu 14.something.










share|improve this question














so I have a simple sh file I want to run whenever someone logs in. I tried adding it to startup applications. This didn't work. I tried editing the .desktop file for the startup application to set Terminal=true. This made it open temporarily but shut it down.
I tried editing .bashrc by adding the command bash /path/to/my/file.sh and it had the same effect. This seems like it should be really simple to do, even in linux, but I have tried lots of ways and had no success. I am on Ubuntu 14.something.







login startup .desktop .sh






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jul 3 '14 at 16:38









user2662920user2662920

612




612








  • 1





    All of those methods should have worked (well, the .bashrc one is only on opening a Terminal; .profile would have been better). What are you doing inside the .sh file? Is the executable bit set? Does it start with #!/bin/bash?

    – saiarcot895
    Jul 3 '14 at 16:41













  • As @saiarcot895 you may forgot to give executable permissions to file.

    – Sudheer
    Jul 3 '14 at 16:43











  • You would be able to find out what filetype it is set to by typing in ls -la

    – ryekayo
    Jul 3 '14 at 16:49











  • Please edit your post and include the script in question. Also, please clarify if you want this to run for a single user or for all users.

    – terdon
    Jul 3 '14 at 16:53














  • 1





    All of those methods should have worked (well, the .bashrc one is only on opening a Terminal; .profile would have been better). What are you doing inside the .sh file? Is the executable bit set? Does it start with #!/bin/bash?

    – saiarcot895
    Jul 3 '14 at 16:41













  • As @saiarcot895 you may forgot to give executable permissions to file.

    – Sudheer
    Jul 3 '14 at 16:43











  • You would be able to find out what filetype it is set to by typing in ls -la

    – ryekayo
    Jul 3 '14 at 16:49











  • Please edit your post and include the script in question. Also, please clarify if you want this to run for a single user or for all users.

    – terdon
    Jul 3 '14 at 16:53








1




1





All of those methods should have worked (well, the .bashrc one is only on opening a Terminal; .profile would have been better). What are you doing inside the .sh file? Is the executable bit set? Does it start with #!/bin/bash?

– saiarcot895
Jul 3 '14 at 16:41







All of those methods should have worked (well, the .bashrc one is only on opening a Terminal; .profile would have been better). What are you doing inside the .sh file? Is the executable bit set? Does it start with #!/bin/bash?

– saiarcot895
Jul 3 '14 at 16:41















As @saiarcot895 you may forgot to give executable permissions to file.

– Sudheer
Jul 3 '14 at 16:43





As @saiarcot895 you may forgot to give executable permissions to file.

– Sudheer
Jul 3 '14 at 16:43













You would be able to find out what filetype it is set to by typing in ls -la

– ryekayo
Jul 3 '14 at 16:49





You would be able to find out what filetype it is set to by typing in ls -la

– ryekayo
Jul 3 '14 at 16:49













Please edit your post and include the script in question. Also, please clarify if you want this to run for a single user or for all users.

– terdon
Jul 3 '14 at 16:53





Please edit your post and include the script in question. Also, please clarify if you want this to run for a single user or for all users.

– terdon
Jul 3 '14 at 16:53










2 Answers
2






active

oldest

votes


















0














When you set Terminal=true in the desktop file, the terminal window by default closes after the "the job has finished". An easy solution is to change your (terminal-) profile settings:




  • open a terminal window, choose Profile Preferences

  • choose "Title & Command" (at least that is what it is in Dutch, the second tab)

  • in the section "when the command has finished" choose "keep terminal window open"


And of course, like you did, in the desktop file, set Terminal=true



enter image description here






share|improve this answer































    -1














    Solution for Question --> "so I have a simple sh file I want to run whenever someone logs in. I tried adding it to startup applications."



    Suppose path of your file is /home/foster/Desktop/script.sh



    First make it executable by :



    $ chmod +x /home/foster/Desktop/script.sh


    Now just Add path of the script to file "/etc/rc.local" :



    sh /home/foster/Desktop/script.sh
    exit 0





    share|improve this answer

























      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "89"
      };
      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',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f491313%2fhow-to-run-a-sh-file-in-terminal-on-login%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      When you set Terminal=true in the desktop file, the terminal window by default closes after the "the job has finished". An easy solution is to change your (terminal-) profile settings:




      • open a terminal window, choose Profile Preferences

      • choose "Title & Command" (at least that is what it is in Dutch, the second tab)

      • in the section "when the command has finished" choose "keep terminal window open"


      And of course, like you did, in the desktop file, set Terminal=true



      enter image description here






      share|improve this answer




























        0














        When you set Terminal=true in the desktop file, the terminal window by default closes after the "the job has finished". An easy solution is to change your (terminal-) profile settings:




        • open a terminal window, choose Profile Preferences

        • choose "Title & Command" (at least that is what it is in Dutch, the second tab)

        • in the section "when the command has finished" choose "keep terminal window open"


        And of course, like you did, in the desktop file, set Terminal=true



        enter image description here






        share|improve this answer


























          0












          0








          0







          When you set Terminal=true in the desktop file, the terminal window by default closes after the "the job has finished". An easy solution is to change your (terminal-) profile settings:




          • open a terminal window, choose Profile Preferences

          • choose "Title & Command" (at least that is what it is in Dutch, the second tab)

          • in the section "when the command has finished" choose "keep terminal window open"


          And of course, like you did, in the desktop file, set Terminal=true



          enter image description here






          share|improve this answer













          When you set Terminal=true in the desktop file, the terminal window by default closes after the "the job has finished". An easy solution is to change your (terminal-) profile settings:




          • open a terminal window, choose Profile Preferences

          • choose "Title & Command" (at least that is what it is in Dutch, the second tab)

          • in the section "when the command has finished" choose "keep terminal window open"


          And of course, like you did, in the desktop file, set Terminal=true



          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jul 3 '14 at 17:12









          Jacob VlijmJacob Vlijm

          64.5k9127223




          64.5k9127223

























              -1














              Solution for Question --> "so I have a simple sh file I want to run whenever someone logs in. I tried adding it to startup applications."



              Suppose path of your file is /home/foster/Desktop/script.sh



              First make it executable by :



              $ chmod +x /home/foster/Desktop/script.sh


              Now just Add path of the script to file "/etc/rc.local" :



              sh /home/foster/Desktop/script.sh
              exit 0





              share|improve this answer






























                -1














                Solution for Question --> "so I have a simple sh file I want to run whenever someone logs in. I tried adding it to startup applications."



                Suppose path of your file is /home/foster/Desktop/script.sh



                First make it executable by :



                $ chmod +x /home/foster/Desktop/script.sh


                Now just Add path of the script to file "/etc/rc.local" :



                sh /home/foster/Desktop/script.sh
                exit 0





                share|improve this answer




























                  -1












                  -1








                  -1







                  Solution for Question --> "so I have a simple sh file I want to run whenever someone logs in. I tried adding it to startup applications."



                  Suppose path of your file is /home/foster/Desktop/script.sh



                  First make it executable by :



                  $ chmod +x /home/foster/Desktop/script.sh


                  Now just Add path of the script to file "/etc/rc.local" :



                  sh /home/foster/Desktop/script.sh
                  exit 0





                  share|improve this answer















                  Solution for Question --> "so I have a simple sh file I want to run whenever someone logs in. I tried adding it to startup applications."



                  Suppose path of your file is /home/foster/Desktop/script.sh



                  First make it executable by :



                  $ chmod +x /home/foster/Desktop/script.sh


                  Now just Add path of the script to file "/etc/rc.local" :



                  sh /home/foster/Desktop/script.sh
                  exit 0






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 8 '16 at 12:16

























                  answered Jul 3 '14 at 17:00









                  vivekyad4vvivekyad4v

                  3091411




                  3091411






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Ask Ubuntu!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f491313%2fhow-to-run-a-sh-file-in-terminal-on-login%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      How to make a Squid Proxy server?

                      Is this a new Fibonacci Identity?

                      19世紀