Can't get autostart to run scripts

I was trying to help my sister get some settings to apply on startup in Lubuntu (24.04.2). We were struggling to get anywhere, so in my own time I decided to run Lubuntu in Gnome’s Boxes and figure out how to get a script -any script at all- to run at startup using autostart, and no matter what I couldn’t get it to do anything.

Here’s what I’m trying to do: I go to LXQT config centre > session > autostart, select LXQT session, press add, and for the command I put: “echo “That’s the way to do it” > Desktop/test-as”.
The command runs flawlessly if I put it directly in the command line and it also works as a .sh, but it doesn’t run at startup and if I go to .config/autostart and manually run the .desktop file that was created for it nothing happens.

What am I doing wrong?

1 Like

Welcome to Ubuntu Discourse :slight_smile:

When you saved the .sh did you make it executable?

chmod +x /path/to/file

I normally save bash scripts in home in a folder called Scripts rather than Desktop.

Not sure if that is the issue here or not.

Hi, thanks. Yes, I chmod’d the script and the script file works fine. In the example I gave in the OP I was pasting the code from the script directly into the autostart’s command box (rather than using a .sh), but I’ve also tried using the “search” button to select a functional .sh (which was kept in home/username), and that didn’t work either

Afaik redirection doesn’t work in autostart commands.
Wrap the command in a shell.

Edit your .desktop file;
Exec=bash -c 'echo "Hello" > ~/Desktop/test.txt'

Also, the LXQT gui is buggy,
it will constantly insert backslashes before
your quotes -every time you save.
So it’s better to keep it simple;
bash -c ~/yourScript.sh
and then do your echo stuff inside the script.

5 Likes

Thanks for the suggestions, but I still can’t get it to work. In autostart my code is now :
bash -c ~/test2.sh
and my .sh is:
Exec=bash -c 'echo "Hello" > ~/Desktop/autotestt.txt'
The .sh doesn’t work if I run it from the console now, it gives the error:

line1: -c: command not found

Wait, my bad, I just realised you meant it would need the exec=bash if the code was still in the .desktop.
I removed exec=bash -c from the .sh and kept the shorter autorun script like you said, and now it works! Thanks!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.