How do I run script on startup to fix screen orientation issue? [duplicate]

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








up vote
-1
down vote

favorite













This question already has an answer here:



  • How to run scripts on start up?

    9 answers



  • How to run xrandr commands at startup in Ubuntu

    3 answers



  • How do I prevent unattended screen rotation at login?

    1 answer



I've be looking for a way to run a script on startup but all old threads I've found on the subject seem to be before systemd came in and none of the answers I've found seem to work anymore. I'm new to Linux operating systems and I'm not sure where to look for instructions on how to do this under systemd.



For a bit of back story I recently replaced Windows on a little tablet/laptop with Ubuntu and I've found that on start up the screen orientation is the wrong way around, meaning every time I log in I have to enter xrandr -o right into the terminal, which is a bit annoying to do every time.



Additionally, if anyone has any resources for beginners entering Linux, I'd love to see them! I'm currently on a university degree and the programming side of things is all done on Ubuntu so it would be great to become more adept at using the system.



Thanks.







share|improve this question














marked as duplicate by dessert, Videonauth, Jacob Vlijm, L. D. James, pa4080 May 28 at 12:56


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • There are tons and tons of Linux Tutorials on the web. Would advise you to start from here.
    – C0deDaedalus
    May 28 at 11:04






  • 1




    This answer on the canonical post I linked covers systemd quite well.
    – dessert
    May 28 at 11:06










  • Xrandr commands, or screen- and keyboard related commands in general are a specific categorie, need a slightly different approach.
    – Jacob Vlijm
    May 28 at 12:04















up vote
-1
down vote

favorite













This question already has an answer here:



  • How to run scripts on start up?

    9 answers



  • How to run xrandr commands at startup in Ubuntu

    3 answers



  • How do I prevent unattended screen rotation at login?

    1 answer



I've be looking for a way to run a script on startup but all old threads I've found on the subject seem to be before systemd came in and none of the answers I've found seem to work anymore. I'm new to Linux operating systems and I'm not sure where to look for instructions on how to do this under systemd.



For a bit of back story I recently replaced Windows on a little tablet/laptop with Ubuntu and I've found that on start up the screen orientation is the wrong way around, meaning every time I log in I have to enter xrandr -o right into the terminal, which is a bit annoying to do every time.



Additionally, if anyone has any resources for beginners entering Linux, I'd love to see them! I'm currently on a university degree and the programming side of things is all done on Ubuntu so it would be great to become more adept at using the system.



Thanks.







share|improve this question














marked as duplicate by dessert, Videonauth, Jacob Vlijm, L. D. James, pa4080 May 28 at 12:56


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • There are tons and tons of Linux Tutorials on the web. Would advise you to start from here.
    – C0deDaedalus
    May 28 at 11:04






  • 1




    This answer on the canonical post I linked covers systemd quite well.
    – dessert
    May 28 at 11:06










  • Xrandr commands, or screen- and keyboard related commands in general are a specific categorie, need a slightly different approach.
    – Jacob Vlijm
    May 28 at 12:04













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite












This question already has an answer here:



  • How to run scripts on start up?

    9 answers



  • How to run xrandr commands at startup in Ubuntu

    3 answers



  • How do I prevent unattended screen rotation at login?

    1 answer



I've be looking for a way to run a script on startup but all old threads I've found on the subject seem to be before systemd came in and none of the answers I've found seem to work anymore. I'm new to Linux operating systems and I'm not sure where to look for instructions on how to do this under systemd.



For a bit of back story I recently replaced Windows on a little tablet/laptop with Ubuntu and I've found that on start up the screen orientation is the wrong way around, meaning every time I log in I have to enter xrandr -o right into the terminal, which is a bit annoying to do every time.



Additionally, if anyone has any resources for beginners entering Linux, I'd love to see them! I'm currently on a university degree and the programming side of things is all done on Ubuntu so it would be great to become more adept at using the system.



Thanks.







share|improve this question















This question already has an answer here:



  • How to run scripts on start up?

    9 answers



  • How to run xrandr commands at startup in Ubuntu

    3 answers



  • How do I prevent unattended screen rotation at login?

    1 answer



I've be looking for a way to run a script on startup but all old threads I've found on the subject seem to be before systemd came in and none of the answers I've found seem to work anymore. I'm new to Linux operating systems and I'm not sure where to look for instructions on how to do this under systemd.



For a bit of back story I recently replaced Windows on a little tablet/laptop with Ubuntu and I've found that on start up the screen orientation is the wrong way around, meaning every time I log in I have to enter xrandr -o right into the terminal, which is a bit annoying to do every time.



Additionally, if anyone has any resources for beginners entering Linux, I'd love to see them! I'm currently on a university degree and the programming side of things is all done on Ubuntu so it would be great to become more adept at using the system.



Thanks.





This question already has an answer here:



  • How to run scripts on start up?

    9 answers



  • How to run xrandr commands at startup in Ubuntu

    3 answers



  • How do I prevent unattended screen rotation at login?

    1 answer









share|improve this question













share|improve this question




share|improve this question








edited May 29 at 12:04









pa4080

11.8k52255




11.8k52255










asked May 28 at 10:37









exitpotato

61




61




marked as duplicate by dessert, Videonauth, Jacob Vlijm, L. D. James, pa4080 May 28 at 12:56


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by dessert, Videonauth, Jacob Vlijm, L. D. James, pa4080 May 28 at 12:56


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • There are tons and tons of Linux Tutorials on the web. Would advise you to start from here.
    – C0deDaedalus
    May 28 at 11:04






  • 1




    This answer on the canonical post I linked covers systemd quite well.
    – dessert
    May 28 at 11:06










  • Xrandr commands, or screen- and keyboard related commands in general are a specific categorie, need a slightly different approach.
    – Jacob Vlijm
    May 28 at 12:04

















  • There are tons and tons of Linux Tutorials on the web. Would advise you to start from here.
    – C0deDaedalus
    May 28 at 11:04






  • 1




    This answer on the canonical post I linked covers systemd quite well.
    – dessert
    May 28 at 11:06










  • Xrandr commands, or screen- and keyboard related commands in general are a specific categorie, need a slightly different approach.
    – Jacob Vlijm
    May 28 at 12:04
















There are tons and tons of Linux Tutorials on the web. Would advise you to start from here.
– C0deDaedalus
May 28 at 11:04




There are tons and tons of Linux Tutorials on the web. Would advise you to start from here.
– C0deDaedalus
May 28 at 11:04




1




1




This answer on the canonical post I linked covers systemd quite well.
– dessert
May 28 at 11:06




This answer on the canonical post I linked covers systemd quite well.
– dessert
May 28 at 11:06












Xrandr commands, or screen- and keyboard related commands in general are a specific categorie, need a slightly different approach.
– Jacob Vlijm
May 28 at 12:04





Xrandr commands, or screen- and keyboard related commands in general are a specific categorie, need a slightly different approach.
– Jacob Vlijm
May 28 at 12:04











2 Answers
2






active

oldest

votes

















up vote
2
down vote



accepted










I have the same issue within Ubuntu 16.04. Apparently it is a bug, something saves wrong value of the display orientation into the file ~/.config/monitors.xml. So if you execute xrandr -o right on startup the orientation value will be override when you login and the file monitors.xml is readied.



To fix this for a certain user, just add the following Cron job - crontab -e:



@reboot sed -i 's#<rotation>.*</rotation>#<rotation>normal</rotation>#' "$HOME/.config/monitors.xml" >/dev/null 2>&1


  • Replace normal with your desired orientation.

  • This command will substitute <rotation>something</rotation> with <rotation>desired value</rotation> within the file ~/.config/monitors.xml.

Unfortunately this workaround will fix the problem only when you start or reboot the system. When you log-out and log-in the problem may appear again. To fix this you can add your xrandr command in the Startup Applications.






share|improve this answer






















  • Xrandr commands, or screen- and keyboard related commands in general are a specific categorie, need a slightly different approach. Your description is correct, but I am not sure the solution is the simplest for the case :)
    – Jacob Vlijm
    May 28 at 12:22











  • @JacobVlijm, the current issue is really annoying... If you just put xrandr command in the Startup applications, when you run the system and log-in - monitors.xml will be executed first and you will get wrong orientation. Then will be executed the xrandr command from Startup applications and the screen will be rotated once again. This take 1-3 second at all an it is comparable with the boot time of fast laptop with SSD...
    – pa4080
    May 28 at 12:31










  • I know, the simplest solution is to add a tiny break to the startup command. askubuntu.com/questions/637911/…
    – Jacob Vlijm
    May 28 at 12:33

















up vote
3
down vote













Example startup script:




  1. First create a systemd startup script eg.disk-space-check.service into /etc/systemd/system/ directory with content:



    [Unit]
    After=mysql.service
    [Service]
    ExecStart=/usr/local/bin/disk-space-check.sh
    [Install]
    WantedBy=default.target



  2. Install systemd service unit and enable it:



    chmod 664 /etc/systemd/system/disk-space-check.service
    systemctl daemon-reload
    systemctl enable disk-space-check.service


More explanation about you can read in this links:



  • How to Write Startup scripts for systemd ?

  • How to auto-execute shell scripts at startup boot on systemd ?





share|improve this answer





























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    I have the same issue within Ubuntu 16.04. Apparently it is a bug, something saves wrong value of the display orientation into the file ~/.config/monitors.xml. So if you execute xrandr -o right on startup the orientation value will be override when you login and the file monitors.xml is readied.



    To fix this for a certain user, just add the following Cron job - crontab -e:



    @reboot sed -i 's#<rotation>.*</rotation>#<rotation>normal</rotation>#' "$HOME/.config/monitors.xml" >/dev/null 2>&1


    • Replace normal with your desired orientation.

    • This command will substitute <rotation>something</rotation> with <rotation>desired value</rotation> within the file ~/.config/monitors.xml.

    Unfortunately this workaround will fix the problem only when you start or reboot the system. When you log-out and log-in the problem may appear again. To fix this you can add your xrandr command in the Startup Applications.






    share|improve this answer






















    • Xrandr commands, or screen- and keyboard related commands in general are a specific categorie, need a slightly different approach. Your description is correct, but I am not sure the solution is the simplest for the case :)
      – Jacob Vlijm
      May 28 at 12:22











    • @JacobVlijm, the current issue is really annoying... If you just put xrandr command in the Startup applications, when you run the system and log-in - monitors.xml will be executed first and you will get wrong orientation. Then will be executed the xrandr command from Startup applications and the screen will be rotated once again. This take 1-3 second at all an it is comparable with the boot time of fast laptop with SSD...
      – pa4080
      May 28 at 12:31










    • I know, the simplest solution is to add a tiny break to the startup command. askubuntu.com/questions/637911/…
      – Jacob Vlijm
      May 28 at 12:33














    up vote
    2
    down vote



    accepted










    I have the same issue within Ubuntu 16.04. Apparently it is a bug, something saves wrong value of the display orientation into the file ~/.config/monitors.xml. So if you execute xrandr -o right on startup the orientation value will be override when you login and the file monitors.xml is readied.



    To fix this for a certain user, just add the following Cron job - crontab -e:



    @reboot sed -i 's#<rotation>.*</rotation>#<rotation>normal</rotation>#' "$HOME/.config/monitors.xml" >/dev/null 2>&1


    • Replace normal with your desired orientation.

    • This command will substitute <rotation>something</rotation> with <rotation>desired value</rotation> within the file ~/.config/monitors.xml.

    Unfortunately this workaround will fix the problem only when you start or reboot the system. When you log-out and log-in the problem may appear again. To fix this you can add your xrandr command in the Startup Applications.






    share|improve this answer






















    • Xrandr commands, or screen- and keyboard related commands in general are a specific categorie, need a slightly different approach. Your description is correct, but I am not sure the solution is the simplest for the case :)
      – Jacob Vlijm
      May 28 at 12:22











    • @JacobVlijm, the current issue is really annoying... If you just put xrandr command in the Startup applications, when you run the system and log-in - monitors.xml will be executed first and you will get wrong orientation. Then will be executed the xrandr command from Startup applications and the screen will be rotated once again. This take 1-3 second at all an it is comparable with the boot time of fast laptop with SSD...
      – pa4080
      May 28 at 12:31










    • I know, the simplest solution is to add a tiny break to the startup command. askubuntu.com/questions/637911/…
      – Jacob Vlijm
      May 28 at 12:33












    up vote
    2
    down vote



    accepted







    up vote
    2
    down vote



    accepted






    I have the same issue within Ubuntu 16.04. Apparently it is a bug, something saves wrong value of the display orientation into the file ~/.config/monitors.xml. So if you execute xrandr -o right on startup the orientation value will be override when you login and the file monitors.xml is readied.



    To fix this for a certain user, just add the following Cron job - crontab -e:



    @reboot sed -i 's#<rotation>.*</rotation>#<rotation>normal</rotation>#' "$HOME/.config/monitors.xml" >/dev/null 2>&1


    • Replace normal with your desired orientation.

    • This command will substitute <rotation>something</rotation> with <rotation>desired value</rotation> within the file ~/.config/monitors.xml.

    Unfortunately this workaround will fix the problem only when you start or reboot the system. When you log-out and log-in the problem may appear again. To fix this you can add your xrandr command in the Startup Applications.






    share|improve this answer














    I have the same issue within Ubuntu 16.04. Apparently it is a bug, something saves wrong value of the display orientation into the file ~/.config/monitors.xml. So if you execute xrandr -o right on startup the orientation value will be override when you login and the file monitors.xml is readied.



    To fix this for a certain user, just add the following Cron job - crontab -e:



    @reboot sed -i 's#<rotation>.*</rotation>#<rotation>normal</rotation>#' "$HOME/.config/monitors.xml" >/dev/null 2>&1


    • Replace normal with your desired orientation.

    • This command will substitute <rotation>something</rotation> with <rotation>desired value</rotation> within the file ~/.config/monitors.xml.

    Unfortunately this workaround will fix the problem only when you start or reboot the system. When you log-out and log-in the problem may appear again. To fix this you can add your xrandr command in the Startup Applications.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited May 28 at 12:21

























    answered May 28 at 11:38









    pa4080

    11.8k52255




    11.8k52255











    • Xrandr commands, or screen- and keyboard related commands in general are a specific categorie, need a slightly different approach. Your description is correct, but I am not sure the solution is the simplest for the case :)
      – Jacob Vlijm
      May 28 at 12:22











    • @JacobVlijm, the current issue is really annoying... If you just put xrandr command in the Startup applications, when you run the system and log-in - monitors.xml will be executed first and you will get wrong orientation. Then will be executed the xrandr command from Startup applications and the screen will be rotated once again. This take 1-3 second at all an it is comparable with the boot time of fast laptop with SSD...
      – pa4080
      May 28 at 12:31










    • I know, the simplest solution is to add a tiny break to the startup command. askubuntu.com/questions/637911/…
      – Jacob Vlijm
      May 28 at 12:33
















    • Xrandr commands, or screen- and keyboard related commands in general are a specific categorie, need a slightly different approach. Your description is correct, but I am not sure the solution is the simplest for the case :)
      – Jacob Vlijm
      May 28 at 12:22











    • @JacobVlijm, the current issue is really annoying... If you just put xrandr command in the Startup applications, when you run the system and log-in - monitors.xml will be executed first and you will get wrong orientation. Then will be executed the xrandr command from Startup applications and the screen will be rotated once again. This take 1-3 second at all an it is comparable with the boot time of fast laptop with SSD...
      – pa4080
      May 28 at 12:31










    • I know, the simplest solution is to add a tiny break to the startup command. askubuntu.com/questions/637911/…
      – Jacob Vlijm
      May 28 at 12:33















    Xrandr commands, or screen- and keyboard related commands in general are a specific categorie, need a slightly different approach. Your description is correct, but I am not sure the solution is the simplest for the case :)
    – Jacob Vlijm
    May 28 at 12:22





    Xrandr commands, or screen- and keyboard related commands in general are a specific categorie, need a slightly different approach. Your description is correct, but I am not sure the solution is the simplest for the case :)
    – Jacob Vlijm
    May 28 at 12:22













    @JacobVlijm, the current issue is really annoying... If you just put xrandr command in the Startup applications, when you run the system and log-in - monitors.xml will be executed first and you will get wrong orientation. Then will be executed the xrandr command from Startup applications and the screen will be rotated once again. This take 1-3 second at all an it is comparable with the boot time of fast laptop with SSD...
    – pa4080
    May 28 at 12:31




    @JacobVlijm, the current issue is really annoying... If you just put xrandr command in the Startup applications, when you run the system and log-in - monitors.xml will be executed first and you will get wrong orientation. Then will be executed the xrandr command from Startup applications and the screen will be rotated once again. This take 1-3 second at all an it is comparable with the boot time of fast laptop with SSD...
    – pa4080
    May 28 at 12:31












    I know, the simplest solution is to add a tiny break to the startup command. askubuntu.com/questions/637911/…
    – Jacob Vlijm
    May 28 at 12:33




    I know, the simplest solution is to add a tiny break to the startup command. askubuntu.com/questions/637911/…
    – Jacob Vlijm
    May 28 at 12:33












    up vote
    3
    down vote













    Example startup script:




    1. First create a systemd startup script eg.disk-space-check.service into /etc/systemd/system/ directory with content:



      [Unit]
      After=mysql.service
      [Service]
      ExecStart=/usr/local/bin/disk-space-check.sh
      [Install]
      WantedBy=default.target



    2. Install systemd service unit and enable it:



      chmod 664 /etc/systemd/system/disk-space-check.service
      systemctl daemon-reload
      systemctl enable disk-space-check.service


    More explanation about you can read in this links:



    • How to Write Startup scripts for systemd ?

    • How to auto-execute shell scripts at startup boot on systemd ?





    share|improve this answer


























      up vote
      3
      down vote













      Example startup script:




      1. First create a systemd startup script eg.disk-space-check.service into /etc/systemd/system/ directory with content:



        [Unit]
        After=mysql.service
        [Service]
        ExecStart=/usr/local/bin/disk-space-check.sh
        [Install]
        WantedBy=default.target



      2. Install systemd service unit and enable it:



        chmod 664 /etc/systemd/system/disk-space-check.service
        systemctl daemon-reload
        systemctl enable disk-space-check.service


      More explanation about you can read in this links:



      • How to Write Startup scripts for systemd ?

      • How to auto-execute shell scripts at startup boot on systemd ?





      share|improve this answer
























        up vote
        3
        down vote










        up vote
        3
        down vote









        Example startup script:




        1. First create a systemd startup script eg.disk-space-check.service into /etc/systemd/system/ directory with content:



          [Unit]
          After=mysql.service
          [Service]
          ExecStart=/usr/local/bin/disk-space-check.sh
          [Install]
          WantedBy=default.target



        2. Install systemd service unit and enable it:



          chmod 664 /etc/systemd/system/disk-space-check.service
          systemctl daemon-reload
          systemctl enable disk-space-check.service


        More explanation about you can read in this links:



        • How to Write Startup scripts for systemd ?

        • How to auto-execute shell scripts at startup boot on systemd ?





        share|improve this answer














        Example startup script:




        1. First create a systemd startup script eg.disk-space-check.service into /etc/systemd/system/ directory with content:



          [Unit]
          After=mysql.service
          [Service]
          ExecStart=/usr/local/bin/disk-space-check.sh
          [Install]
          WantedBy=default.target



        2. Install systemd service unit and enable it:



          chmod 664 /etc/systemd/system/disk-space-check.service
          systemctl daemon-reload
          systemctl enable disk-space-check.service


        More explanation about you can read in this links:



        • How to Write Startup scripts for systemd ?

        • How to auto-execute shell scripts at startup boot on systemd ?






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited May 28 at 12:33









        pa4080

        11.8k52255




        11.8k52255










        answered May 28 at 10:56









        mariaczi

        31915




        31915












            Popular posts from this blog

            pylint3 and pip3 broken

            Missing snmpget and snmpwalk

            How to enroll fingerprints to Ubuntu 17.10 with VFS491