[SOLVED] bash script and Pulse problem

[SOLVED] bash script and Pulse problem

Postby zeke » Dec 5th, '13, 19:16

I have a script I adapted that records the current main channel volume of alsamixer, sets the volume to a particular level, plays a local .wav file, then resets the volume:

Code: Select all

#!/bin/bash
#

#####################################################################
# Get current volume.
function get_volume()
{
    mixer=$(amixer get Master | grep 'Front Left:')
    echo $mixer | cut -d ' ' -f 4
}


#####################################################################
# Set volume.
function set_volume()
{
    amixer cset iface=MIXER,name="Master Playback Volume" $1 >/dev/null
}


if [[ $(basename $0 .sh) == 'sound' ]]; then
echo "In the script"

    sound_file=/home/brett/Downloads/Heartbeat120.wav
    if [[ "$1" ]]; then sound_file="$1"; fi

    ovol=$(get_volume)
    echo "Current volume: $ovol"
    vol=22100
    set_volume $vol
    echo "Playing at: $vol"
    aplay $sound_file
    sleep 2

    vol=45215
    echo "Playing at: $vol"
    set_volume $vol
    aplay $sound_file
    sleep 2
    echo "Again at: $ovol"
    set_volume $ovol
fi
   

# vim: tabstop=4: shiftwidth=4: noexpandtab:
# kate: tab-width 4; indent-width 4; replace-tabs false;


When I run this script from the CLI, it works perfectly. I want to automate it using cron, but when I add it to crontab, when the script is called I get this error message in /var/log/syslog:

Code: Select all
$ tail  /var/log/syslog
Dec  5 11:11:01 localhost pulseaudio[18163]: [pulseaudio] socket-server.c: bind(): Address already in use
Dec  5 11:11:01 localhost pulseaudio[18163]: [pulseaudio] module.c: Failed to load module "module-esound-protocol-unix" (argument: ""): initialization failed.
Dec  5 11:11:01 localhost pulseaudio[18163]: [pulseaudio] main.c: Module load failed.
Dec  5 11:11:01 localhost pulseaudio[18163]: [pulseaudio] main.c: Failed to initialize daemon.
Dec  5 11:11:01 localhost pulseaudio[18160]: [pulseaudio] main.c: Daemon startup failed.
Dec  5 11:11:02 localhost pulseaudio[18171]: [pulseaudio] socket-server.c: bind(): Address already in use
Dec  5 11:11:02 localhost pulseaudio[18171]: [pulseaudio] module.c: Failed to load module "module-esound-protocol-unix" (argument: ""): initialization failed.
Dec  5 11:11:02 localhost pulseaudio[18171]: [pulseaudio] main.c: Module load failed.
Dec  5 11:11:02 localhost pulseaudio[18171]: [pulseaudio] main.c: Failed to initialize daemon.
Dec  5 11:11:02 localhost pulseaudio[18168]: [pulseaudio] main.c: Daemon startup failed.


Audio is working fine otherwise, though....

I have had sporadic Pulseaudio problems since installing MGA3 on this machine, where I get a PA crash and restarting it leads to similar error messages but no audio from any source. The only fix I have found is to do two reboots (one is never enough).

Can anyone help me understand what is happening and why?
Last edited by zeke on Jan 9th, '14, 23:52, edited 1 time in total.
zeke
 
Posts: 107
Joined: Jun 14th, '11, 17:42

Re: bash script and Pulse problem

Postby jiml8 » Dec 5th, '13, 21:52

The cron job is probably running in a different context. The default crontab is a root crontab. You need to set up a crontab for your user name. That should fix it, I think.
jiml8
 
Posts: 1253
Joined: Jul 7th, '13, 18:09

Re: bash script and Pulse problem

Postby zeke » Dec 5th, '13, 22:10

sorry I didn't specify, this is running under my regular user account. There is no root crontab on this machine.
zeke
 
Posts: 107
Joined: Jun 14th, '11, 17:42

Re: bash script and Pulse problem

Postby doktor5000 » Dec 6th, '13, 00:10

This will not run within your desktop session, and your desktop session has access to pulse server.

What exactly do you want to achieve with that script?
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 17630
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

Re: bash script and Pulse problem

Postby zeke » Dec 6th, '13, 00:41

I want the script to play a wav at a particular volume (regardless of the volume setting at runtime) and then reset the volume to its previous level. I want this to occur each hour between 8am and 5pm on weekdays.
I am open to other means to do this, but it seems like a no-brainer to use cron?
zeke
 
Posts: 107
Joined: Jun 14th, '11, 17:42

Re: bash script and Pulse problem

Postby doktor5000 » Dec 6th, '13, 01:40

Have you tried to use
Code: Select all
paplay
for that, without fiddling with the mixer? Directly specify the volume and also add -l to the shebang so that bash is invoked as login shell.
That way your script would be a simple one-liner. Sorry but I don't understand that complexity, why you would want that.

E.g. this would play the sound at 80% volume.
Code: Select all
paplay --volume=52429 /usr/share/sounds/freedesktop/stereo/alarm-clock-elapsed.oga
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 17630
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

Re: bash script and Pulse problem

Postby zeke » Dec 6th, '13, 16:04

Thanks Doktor,

I will play around with that. Where should I add the -l? is that in the crontab call or in the paplay call inside the script?
zeke
 
Posts: 107
Joined: Jun 14th, '11, 17:42

Re: bash script and Pulse problem

Postby doktor5000 » Dec 6th, '13, 16:09

zeke wrote:I have a script ...
Code: Select all
#!/bin/bash


As mentioned, append it to the shebang:
Code: Select all
#!/bin/bash -l
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 17630
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

Re: bash script and Pulse problem

Postby zeke » Dec 6th, '13, 17:28

So here is the script:
Code: Select all
#!/bin/bash -l
#
paplay --volume=52429 /home/****/Downloads/Heartbeat120.wav


The script works if I call it from the command line.

Here is my crontab:

Code: Select all
25 * * * * /home/*****/alarm.sh


But the script did not play at 9:25:00, giving the same error message as before:
Code: Select all
 tail  /var/log/syslog
Dec  6 09:25:02 localhost pulseaudio[13893]: [pulseaudio] socket-server.c: bind(): Address already in use
Dec  6 09:25:02 localhost pulseaudio[13893]: [pulseaudio] module.c: Failed to load module "module-esound-protocol-unix" (argument: ""): initialization failed.
Dec  6 09:25:02 localhost pulseaudio[13893]: [pulseaudio] main.c: Module load failed.
Dec  6 09:25:02 localhost pulseaudio[13893]: [pulseaudio] main.c: Failed to initialize daemon.
Dec  6 09:25:02 localhost pulseaudio[13890]: [pulseaudio] main.c: Daemon startup failed.
Dec  6 09:25:02 localhost postfix/pickup[12715]: DA4845F4F8: uid=501 from=<brett>
Dec  6 09:25:02 localhost postfix/cleanup[13517]: DA4845F4F8: message-id=<20131206152502.DA4845F4F8@localhost.localdomain>
Dec  6 09:25:02 localhost postfix/qmgr[2657]: DA4845F4F8: from=<brett@localhost.localdomain>, size=698, nrcpt=1 (queue active)
Dec  6 09:25:02 localhost postfix/local[13518]: DA4845F4F8: to=<brett@localhost.localdomain>, orig_to=<brett>, relay=local, delay=0.13, delays=0.08/0/0/0.04, dsn=2.0.0, status=sent (delivered to mailbox)
Dec  6 09:25:02 localhost postfix/qmgr[2657]: DA4845F4F8: removed
You have new mail in /var/spool/mail/brett
zeke
 
Posts: 107
Joined: Jun 14th, '11, 17:42

Re: bash script and Pulse problem

Postby zeke » Dec 12th, '13, 22:00

After a reboot, the cron process worked twice, then pulse audio crashed again. I will reboot twice and see if the sounds returns.
zeke
 
Posts: 107
Joined: Jun 14th, '11, 17:42

Re: bash script and Pulse problem

Postby doktor5000 » Dec 13th, '13, 00:30

What desktop environment do you use? Wouldn't it be a better idea to use the DE tools for this, like kalarm or gnome schedule? See my comments about the why further above.
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 17630
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

Re: bash script and Pulse problem

Postby zeke » Dec 13th, '13, 17:51

I use KDE. I will try kalarm, thanks! Still frustrated by the frequent Pulse crashes. Would it be possible to try to reinstall pulse and the default pulse settings without a complete system wipe? I have tried to uninstall and reinstall the pulse rpms, but I am still experiencing the crashes. I never had the problem in MGA1 or MGA2 on this same machine.

EDIT: Ok, I installed kalarm, and set it up, but when the alarm is triggered (or when I manually trigger it with the 'TRY' button), it sets all channels in kmix to 0 volume. It does this with the 'set volume' box ticked and unticked. I don't understand this behavior. If I use a sound file that is long enough, and I turn the kmix channels back up, the sound IS playing.

Edit2: Once the sound file ended, kmix channels again returned to 0 with no user involvement
zeke
 
Posts: 107
Joined: Jun 14th, '11, 17:42

Re: bash script and Pulse problem

Postby doktor5000 » Dec 14th, '13, 00:41

Hmmm, just tried to reproduce via the user crontab and got the same result, as mentioned it's probably about permissions and session control which is not the same in cron environment. But it works when run as at job, after installing at and service atd start this works:

Code: Select all
[doktor5000@Mageia3 ~]$ echo "paplay --volume=52429 /usr/share/sounds/freedesktop/stereo/alarm-clock-elapsed.oga" | at now
warning: commands will be executed using (in order) a) $SHELL b) login shell c) /bin/sh
job 2 at Fri Dec 13 23:40:00 2013
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 17630
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

Re: bash script and Pulse problem

Postby jiml8 » Dec 14th, '13, 20:36

Try attaching gdb to the running pulseaudio server so you will at least know why it crashed. The traceback from that, even without symbols, could prove enlightening. And if you were to compile your own pulseaudio server with symbols in it, you would probably learn everything you need to know.

Pulse works great here; seldom crashes (though there are some flash sites that can mess it up sometimes).
jiml8
 
Posts: 1253
Joined: Jul 7th, '13, 18:09

Re: bash script and Pulse problem

Postby doktor5000 » Dec 15th, '13, 01:49

jiml8 wrote:And if you were to compile your own pulseaudio server with symbols in it, you would probably learn everything you need to know.

No need to, if you run a program inside gdb it will tell you which debuginfo packages to install,
which you can conveniently feed to urpmi. Then nearly all symbols are available.
Also check https://wiki.mageia.org/en/Debugging_software_crashes

Example with pulse:

[doktor5000@Mageia3 ~]$ ps -ef | grep -v grep | grep pulseaudio
500 2225 1 0 Dec13 ? 00:09:57 /usr/bin/pulseaudio --start --log-target=syslog


[doktor5000@Mageia3 ~]$ gdb /usr/bin/pulseaudio 2225
GNU gdb (GDB) 7.5.1-7.mga3 (Mageia release 3)
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-mageia-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /usr/bin/pulseaudio...Reading symbols from /usr/bin/pulseaudio...(no debugging symbols found)...done.
(no debugging symbols found)...done.
[...]
Missing separate debuginfos, use: debuginfo-install pulseaudio-3.0-7.mga3.x86_64
(gdb) q
A debugging session is active.

Inferior 1 [process 2225] will be detached.

Quit anyway? (y or n) y
Detaching from program: /usr/bin/pulseaudio, process 2225


Now you may need to enable debug repo for core_release via drakrpm-edit-media

Code: Select all
[doktor5000@Mageia3 ~]$ sudo debuginfo-install pulseaudio-3.0-7.mga3.x86_64
    ftp://ftp-stud.hs-esslingen.de/pub/Mirrors/Mageia/distrib/3/x86_64/media/debug/core/release/pulseaudio-debuginfo-3.0-7.mga3.x86_64.rpm
pulseaudio-debuginfo-3.0-7.mga3.x86_64.rpm von /var/cache/urpmi/rpms wird installiert                                                                                 
Vorbereiten …                    #####################################################################################################################################
      1/1: pulseaudio-debuginfo  #####################################################################################################################################


When gdb runs the next time, it will show recursive list of required debuginfo packages:

Code: Select all
[...]
Missing separate debuginfos, use: debuginfo-install glibc-2.17-7.2.mga3.x86_64 lib64alsa2-1.0.26-7.mga3.x86_64 lib64asyncns0-0.8-5.mga3.x86_64 lib64dbus1_3-1.6.8-4.1.mga3.x86_64 lib64flac8-1.2.1-13.mga3.x86_64 lib64ice6-1.0.8-3.mga3.x86_64 lib64json2-0.11-0.3.mga3.x86_64 lib64ltdl7-2.4.2-10.mga3.x86_64 lib64ogg0-1.3.0-2.mga3.x86_64 lib64orc0.4_0-0.4.16-3.mga3.x86_64 lib64samplerate0-0.1.8-2.mga3.x86_64 lib64sm6-1.2.1-4.mga3.x86_64 lib64sndfile1-1.0.25-2.mga3.x86_64 lib64speex1-1.2-0.rc1.7.mga3.x86_64 lib64systemd-daemon0-195-22.1.mga3.x86_64 lib64systemd-login0-195-22.1.mga3.x86_64 lib64tdb1-1.2.11-2.mga3.x86_64 lib64udev1-195-22.1.mga3.x86_64 lib64uuid1-2.22.2-5.mga3.x86_64 lib64vorbis0-1.3.3-3.mga3.x86_64 lib64vorbisenc2-1.3.3-3.mga3.x86_64 lib64wrap0-7.6-43.mga3.x86_64 lib64x11_6-1.6.0-1.mga3.x86_64 lib64xau6-1.0.7-2.mga3.x86_64 lib64xcb1-1.9.1-1.mga3.x86_64 lib64xdmcp6-1.1.1-3.mga3.x86_64


Also here pulse doesn't crash, it's just that from the cron session there are no proper permissions/acls available.
The crash from the OP must have a different reason, maybe because of the use of amixer or using Alsa/ESD directly.
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 17630
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

Re: bash script and Pulse problem

Postby zeke » Dec 16th, '13, 17:48

Doktor - reproduced your commands, but I cannot find pulseaudio-debuginfo in the repos (see below)?

Also, I have atd running at boot, but when I run:
Code: Select all
echo "paplay --volume=52429 /usr/share/sounds/freedesktop/stereo/alarm-clock-elapsed.oga" | at now
warning: commands will be executed using (in order) a) $SHELL b) login shell c) /bin/sh
job 6 at Mon Dec 16 09:44:00 2013


kmix again gets muted (on all channels). I tried to play a longer file and turn up the volume while it was playing, but I heard no sound.

Code: Select all
[brett@localhost ~]$ ps -ef | grep -v grep | grep pulseaudio
brett     3776     1  0 Dec13 ?        00:00:01 /usr/bin/pulseaudio --start --log-target=syslog
[brett@localhost ~]$ gdb /usr/bin/pulseaudio 3776
GNU gdb (GDB) 7.5.1-7.mga3 (Mageia release 3)
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-mageia-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /usr/bin/pulseaudio...Reading symbols from /usr/bin/pulseaudio...(no debugging symbols found)...done.
....
[root@localhost brett]# debuginfo-install pulseaudio-3.0-7.mga3.x86_64
No package named pulseaudio-debuginfo
Something went wrong, make sure your Debug media are configured properly
[root@localhost brett]#

zeke
 
Posts: 107
Joined: Jun 14th, '11, 17:42

Re: bash script and Pulse problem

Postby doktor5000 » Dec 16th, '13, 18:32

As with the crash, you should first fix your overall sound setup before continuing with anything else.

That is, remove/move away at least those for your user:

Code: Select all
~/.pulse-cookie
~/.config/pulse


And revert any other changes related to sound you might have made since installation, e.g. kmix, global pulse config ...

For the debuginfo packages, seems you only read half the instruction. If you don't have the debug repos enabled, packages will not be available. Simple as that.
Anyways that will probably only lead to wrong information, first you should fix your sound setup so you're back at the Mageia default
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 17630
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

Re: bash script and Pulse problem

Postby zeke » Dec 17th, '13, 18:40

I did delete ~/.config/pulse
I had no .pulse-cookie directory.
I also reset my kmix keymappings to default.
I rebooted just to get all relevant processes restarted, then opened kalarm and clicked the "Try" button.

Kmix volume was again muted and I got this popup message:
Code: Select all
KDE detected that one or more internal devices were removed.
Do you want KDE to permanently forget about these devices?
This is the list of devices KDE thinks can be removed:
Capture: Default ALSA Output (currently PulseAudio Sound Server)
Capture: PulseAudio Sound Server
Output: Default ALSA Output (currently PulseAudio Sound Server)
Output: HDA NVidia, ALC888 Analog (Default Audio Device)
Output: PulseAudio Sound Server


I tried to "Try" the alarm again with the "Set Volume" button unticked, the behavior was unchanged.

If I turn the kmix volume up while the alarm is playing I do hear the sound.

Edit: 10-min later I tried to watch a youtube video, but had no sound, even though I had turned kmix volume back up. I opened PulseAudio Volume control and got the Pulse Audio has crashed. Whenever this happens I have had to reboot TWO times in order to regain sound. VERY frustrating....Put me in the anti-Pulse category.....Why is it better than just ALSA again?
zeke
 
Posts: 107
Joined: Jun 14th, '11, 17:42

Re: bash script and Pulse problem

Postby doktor5000 » Dec 17th, '13, 20:55

Well, I've never had issues with pulse, and never had to reboot. But I also never fiddled around with alsamixer/amixer or whatever.

It's better because it allows to switch streams between devices during play, it supports transparent transition via network, easy integration with e.g. bluetooth but anyways.
As you're in the anti-category, you'll just ignore and complain, so be it.

Please mark the thread accordingly by editing the topic of the first post and prefix it by [DONE], thanks
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 17630
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

Re: bash script and Pulse problem

Postby zeke » Dec 17th, '13, 22:42

Thanks Doktor - I am only partly serious. I have appreciated pulse in the past, but I am frustrated with it presently.

The issue is still not done though.....

I still cannot schedule a recurring sound to play. Using kalarm results in kmix muting all channels and crashing Pulse.

Also, is there something else I can try to respwan Pulse besides 2 reboots?
Last edited by zeke on Dec 17th, '13, 22:55, edited 1 time in total.
zeke
 
Posts: 107
Joined: Jun 14th, '11, 17:42

Re: bash script and Pulse problem

Postby doktor5000 » Dec 17th, '13, 22:50

zeke wrote:I still cannot schedule a recurring sound to play. Using kalarm results in kmix muting all channels and crashing Pulse.

What I've mentioned before, get your basic sound setup fixed. As kalarm plays and event sound, the volume you set in kalarm
is relative to the global volume setting for event sounds. Playing an alarm via kalarm works fine here and pulse never crashed for me.
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 17630
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

Re: bash script and Pulse problem

Postby zeke » Dec 17th, '13, 23:39

Besides deleting the dirs you mention, what else can I do to accomplish that besides a complete wipe and reinstall?
zeke
 
Posts: 107
Joined: Jun 14th, '11, 17:42


Return to Sound

Who is online

Users browsing this forum: No registered users and 1 guest