Autostart does not work (works ok in openSUSE Leap 15.1)

I have Creative Gigaworks T20 speakers connected to my Tumbleweed. This speaker has an auto power management feature which complies with energy efficiency regulation required by certain regions (Europe). This means that the speaker will automatically shut off in 10 minutes if no sound is transmitted to the speakers.

I thought I’d make a little script that plays a little bit of audio and I was cheating on the speaker to stay on. This worked fine in openSUSE Leap 15.1, but will no longer work on Tumbleweed after the upgrade.

This is my script (wakeup-speakers.sh file)

while true; do
mplayer /home/raija/skriptit/creative/20Hz_TestTone2_4.mp3
sleep 9m
done

And it can be found in ~/.config/autostart-scripts. The file itself work ok.

I can find it in messages (/var/log/) but no error message?
messages:2020-01-27T00:13:59.910977+02:00 kone3 ksmserver[1640]: ksmserver: Starting autostart script “/home/raija/.config/autostart-scripts/wakeup-speakers.sh”

How should I change my script or what I should do?

While this won’t help you, because the problem cause is most probably somewhere else, a script should always start with a so called “shebang”, that indentifies which interpreter to use. For a bash script this is

#!/bin/bash

And this should be the first line in your script.

Also there is an important, but not easy to find feature on the forums.

Please in the future use CODE tags around copied/pasted computer text in a post. It is the # button in the tool bar of the post editor. When applicable copy/paste complete, that is including the prompt, the command, the output and the next prompt.

An example is here: Using CODE tags Around your paste.

In your case, that should have been

cat ~/.config/autostart-script/wakeup-speakers.sh

which would have spared you a lot of typing because the path to the file is clear then without doubt (or typing errors).

Thank you for your advices. I try to make myself as clear as possible but I failed.

You did not realy fail, I think your question is clear enough and also documented. I only gave some general advice for the future.

I hope that others (specialy TW users, I am not one) will soon come to help you.

I just ran a quick test on my Tumbleweed machine The while loop runs as expected while the user is logged into a Plasma5 session.
Did you remember to make the scriot executable?


sysman@iMac-testing:~> cat /etc/os-release |grep -i "# ver"
# VERSION="20200124"

sysman@iMac-testing:~> lh .config/autostart-scripts/while-test
-rwxr--r-- 1 sysman wheel 81 Jan 28 11:52 .config/autostart-scripts/while-test

sysman@iMac-testing:~> cat .config/autostart-scripts/while-test
#! /bin/dash
while true; do
touch /home/sysman/tmp/while-test.out
sleep 1m
done

sysman@iMac-testing:~> lh ~/tmp/
total 0
drwxr-xr-x 1 sysman wheel  98 Jan 28 11:55 .
drwxr-xr-x 1 sysman wheel 558 Jan 28 11:55 ..
drwxr-xr-x 1 sysman wheel   0 Jan 25 13:09 anæsthesia
drwxr-xr-x 1 sysman wheel  16 Jan 24 09:45 déjà
drwxr-xr-x 1 sysman wheel   0 Jan 25 13:10 slàinte-mhath
drwxr-xr-x 1 sysman wheel  16 Jan 24 10:24 test
-rw-r--r-- 1 sysman wheel   0 Jan 28 12:06 while-test.out

sysman@iMac-testing:~> date
Tue 28 Jan 12:07:12 GMT 2020
 
sysman@iMac-testing:~> 

dash? .

The dash shell is like a junior bash. It has a much smaller footprint and 90% of the capability. I started using it when there was a security threat with bash a few years ago. As far as I can tell all dash scripts run unaltered in bash.

I wasted half an hour searching the dash command on the internet. :frowning:
But I managed to get the script work. And the reason was really simple, wrong file protection. :slight_smile:

raija@kone3:~/skriptit/creative> cat wakeup-speakers.sh  
#! /bin/bash
while true; do
    mplayer /home/raija/skriptit/creative/30Hz_TestTone2_4.mp3
    sleep 9m
done
raija@kone3:~/skriptit/creative> la 30*.mp3              
-rwxrwxr-x 1 raija users 69579 26. 9. 14:36 30Hz_TestTone2_4.mp3
-rw-r--r-- 1 raija users 37547 12. 8. 14:09 30Hz_TestTone3_2.mp3 <-- kääk!
raija@kone3:~/skriptit/creative> 

Both MP3 files were done at the same time with Audacity. I change the 30Hz_TestTone2_4.mp3 with chmod command.

Quibbling and may not be required,
Ordinarily before a conditional statement like while is to be run,
Typically I find that the variable to be tested needs to be instantiated and set to an initial value.
Otherwise, although in most cases the value might be what is desired there is no guarantee that’d be so.

TSU

With “while true” I thought that the condition was the existence of the loop itself. That would be set by calling (running) the script.

What puzzles me (and I want to test later) is the apparent requirement for a sound file to be executable when fed to a player from a script.

true is a program that always exits with return code 0.

which true

and it has a man page.
Thus “while true” never stops.

I have seen other “improper” use of the x-bits by applications, but this is indeed strange.

But
If “/usr/bin/true” is renamed, then “while true;do touch ~/tmp/while-loop.out; sleep 3; done &” still executes.

And
<https://www.gnu.org/software/coreutils/true&gt;

In most modern shells, true is a built-in command, so when you use ‘true’ in a script, you’re probably using the built-in command, not the one documented here.

No need to go elswhere, just use

man true

which will present you the man page belonging to the version of the tool on your system.

But indeed, a similar statement is there. Conclusion after your test? Probably it is builtin in the shell you use. Maybe you will find that listed in the man page of that shell.
Such often used programs are often made builtins to avoid loading such a program thousands of time.

But the function is the same: Do nothing, return success.

Same for e.g. the command.

And btw, you can find out if a command will be interpreted by the running shell as a builtin, an alias, or an executable file with

henk@boven:~> type true
true is een ingebouwde shell-functie
henk@boven:~> LANG=C type true
true is a shell builtin
henk@boven:~>

Your test works for these shells – bash, busybox (ash), dash, fish3, ksh and zsh, which all have built-in true.
There is no “type” or equivalent for “tcsh” (or “csh”), which is the only shell I found that appears to use the coreutils true. This can be shown with “ true --version”.


/home/rayh% true --version
true (GNU coreutils) 8.29
Copyright (C) 2017 Free Software Foundation, Inc.
...
Written by Jim Meyering.
/home/rayh%