Score:1

Autostart issues running simple xrandr script on start up

jp flag

I've created a simple startup script so that I can use my Ultrawide Monitor with Ubuntu 21.04 (should be similar with the previous version as well). However when I configured this script to be run on startup using 'Autostart' I get an error upon startup instead with the script unable to run. Manually running the script works fine - It's a pain to run it on every start manually....

Anyhow I get this error:

Warning: Could not start program '/home/user/scripts/2560x1080.sh' with arguments '/home/user/scripts/2560x1080.sh'.

Warning: execve: Exec format error

Also, here's the simple script:

#! /bin/bash
#cd /home/user/scripts/
xrandr --newmode "2560x1080_60.00" 230.00  2560 2720 2992 3424  1080 1083 1093 1120 -hsync +vsync
xrandr --addmode HDMI-2 2560x1080_60.00
xrandr --output HDMI-2 --mode 2560x1080_60.00

Thanks in advance

conmak avatar
in flag
Have you tried chronjobs to initialize this script?
sudodus avatar
jp flag
Maybe these links: [link 1](https://askubuntu.com/questions/1353879/lubuntu-20-04-run-a-script-at-login-which-executes-in-a-terminal-window/1354182#1354182) and [link 2](https://askubuntu.com/questions/1251814/xrandr-command-in-startup-script-has-no-effect-but-script-does-run-and-command/1251882#1251882) can help you. The method is tested on verson 20.04 LTS of Ubuntu and Lubuntu.
Hamm avatar
jp flag
Thanks for the crontab suggestion! Adding "@reboot sleep 10 && /home/user/scripts/2560x1080.sh" (no quotes) to the end of crontab didn't work and didn't provide an error message so I have no idea what went a rye :[ This is actually on KDE or Kubuntu...
Organic Marble avatar
us flag
Are you trying to run the script on *startup* or on *login*?
Hamm avatar
jp flag
I'm trying to run this on startup. I just want the monitor to work on it's native ultrawide resolution on startup. Am I creating a new "startscript.sh" that runs my 2562x1080.sh script that crontab will run?
Score:0
in flag

Have you tried a cronjob yet?

You can use crontab for this:

crontab -e

At the bottom of the file you can add an item to run at reboot:

EG:

@reboot /home/{your user}/scripts/startscript.sh

Note: This may run before all of dependencies load. You may want to run the shell script asychronously (eg using & in bash) and add a sleep time to your shell script.

Note: You may want to play around with permissions a bit depending on if you want to run with sudo.

Note: sudo crontab -e is different than crontab -e

Edit:

To add logging to your startscript.sh you can try piping the output of commands to a log file like this: /home/user/scripts/startscript.sh

#!/bin/bash
# Source your bashrc for environment variables
# Note this uses . as source (old school unix) 
# because the source command might not be available depending on the OS
. /home/user/.bashrc
sleep 30
echo "Starting Log" > /home/user/scripts/log.txt
/home/user/scripts/myscript.sh >> /home/user/scripts/log.txt

Note: Paths should be absolute in chronjobs.

sudodus avatar
jp flag
Did you try to run [a script with] `xrandr` from `crontab @reboot`? A script with `xrandr` works for me from `autostart`.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.