As mentioned already here in the forum's 10002'nd thread (!
![Big Smile :D](./images/smilies/biggrin.gif)
)
Anyone else got this "the token was outdated" forum posting loop bug? - I enhanced my "beep" script to add some more error handling.
Here the original:
Code: Select all
#!/bin/sh
# V0.2: changed "$wavfile" to "$soundfile"
soundfile=/mnt/sda2/sound/notification_-12dB.mp3
if [ -f "$soundfile" ]; then
#echo aplay "$wavfile"
mpg123 "$soundfile" 2>/dev/null
else
echo "Soundfile $soundfile not found!"
fi
and here the enhanced version, hopefully able to give you some ideas about error handling. In case of the
beep script it is less necessary, but a good way of learning about error handling in my book.
Code: Select all
#!/bin/sh
# V0.2: changed "$wavfile" to "$soundfile"
# V0.3: added return value error handling due to bug when executed by root
soundfile=/mnt/sda2/sound/notification_-12dB.mp3
if [ -f "$soundfile" ]; then
mpg123 "$soundfile" 2>/dev/null
declare -i return=$?
if [ $return -ne 0 ]; then
echo "mpg123 returns non-zero value of '$return'.
Possible reasons: $0 started as root."
exit $return
fi
else
echo "Soundfile $soundfile not found!"
exit 1
fi
(I also removed the obsolete line starting with aplay since aplay can only handle voc, wav, raw or au files but no mp3 nor aac nor webm [webm can be video only, video and audio and also audio only])
And yes, unfortunately I cannot run any of the beep variants as root, not even started as a plain terminal command. Since 2>/dev/null erases all info of what mpg123 might complain about, here you have what mpg123 gives as the issue when run as root without the error redirection into the void:
Code: Select all
root@porteus:/usr/local/bin# mpg123 /mnt/sda2/sound/notification_-12dB.mp3
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3
version 1.29.3; written and copyright by Michael Hipp and others
free software (LGPL) without any warranty but with best wishes
[src/libout123/modules/pulse.c:open_pulse():170] error: No PulseAudio running. I will not accidentally trigger starting one.
[src/libout123/libout123.c:check_output_module():982] error: Module 'pulse' device open failed.
[src/libout123/libout123.c:out123_open():482] error: Found no driver out of [pulse] working with device <default>.
main: [src/mpg123.c:check_fatal_output():331] error: out123 error 3: failure loading driver module
![Image](http://a.deviantart.net/avatars/r/u/runcryplz.gif)
_____________________________________________
I cannot present you the sound played as user guest when giving you the [
code
] info of what the terminal reports, but this is what gets reported when
beep was executed as guest and as root, also checking for beep's return value both as guest and as root.
As guest:
Code: Select all
guest@porteus:/usr/local/bin$ beep
guest@porteus:/usr/local/bin$ echo $?
0
guest@porteus:/usr/local/bin$
and as root:
Code: Select all
root@porteus:/usr/local/bin# beep
mpg123 returns non-zero value of '255'.
Possible reasons: /usr/local/bin/beep started as root.
root@porteus:/usr/local/bin# echo $?
255
root@porteus:/usr/local/bin#
_____________________________________________
In case you might wonder:
In the other thread the sound file has -15dB in its name while here it has -12dB. Reason is: I was a bit inaccurate in giving you the code of "beep" in the "Anyone else got this "the token was outdated" forum posting loop bug?" thread, since the difference between the two files did not matter in that post.
The truth is: beep uses the -12dB variant (a bit louder) while a script called beep
2 uses the -15dB variant (a bit less loud)
Look for yourself:
Code: Select all
root@porteus:/usr/local/bin# diff beep beep2
4c4
< soundfile=/mnt/sda2/sound/notification_-12dB.mp3
---
> soundfile=/mnt/sda2/sound/notification_-15dB.mp3