-1

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.

3
  • There are tons and tons of Linux Tutorials on the web. Would advise you to start from here. May 28, 2018 at 11:04
  • 1
    This answer on the canonical post I linked covers systemd quite well.
    – dessert
    May 28, 2018 at 11:06
  • Xrandr commands, or screen- and keyboard related commands in general are a specific categorie, need a slightly different approach. May 28, 2018 at 12:04

2 Answers 2

3

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:

0
2

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.

3
  • 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 :) May 28, 2018 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, 2018 at 12:31
  • I know, the simplest solution is to add a tiny break to the startup command. askubuntu.com/questions/637911/… May 28, 2018 at 12:33

Not the answer you're looking for? Browse other questions tagged .