- 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?