On 3/21/23 21:32, Eyal Lebedinsky wrote:
On 22/03/2023 13.57, ToddAndMargo via users wrote:
> On 3/21/23 01:04, Eyal Lebedinsky wrote:
>>
>> On 21/03/2023 17.50, ToddAndMargo via users wrote:
>>> On 3/20/23 21:13, Eyal Lebedinsky wrote:
>>>> On 20/03/2023 17.22, Eyal Lebedinsky wrote:
>>>>> Fedora 36 up-to-date.
>>>>>
>>>>> $ uname -a
>>>>> Linux e4.eyal.emu.id.au 6.1.15-100.fc36.x86_64 #1 SMP
>>>>> PREEMPT_DYNAMIC Fri Mar 3 17:22:46 UTC 2023 x86_64 x86_64 x86_64
>>>>> GNU/Linux
>>>>>
>>>>> I have a script running as root (using sudo) and in it I play a
sound
>>>>> paplay /audio/ogg/beginning.ogg
>>>>> and it always worked.
>>>>>
>>>>> Then a few days ago it stopped and I now get an error. Something
>>>>> changed.
>>>>>
>>>>> $ sudo paplay /audio/ogg/beginning.ogg
>>>>> Connection failure: Connection refused
>>>>> pa_context_connect() failed: Connection refused
>>>>>
>>>>> $ sudo ogg123 -q /audio/ogg/beginning.ogg
>>>>> ALSA lib pulse.c:242:(pulse_connect) PulseAudio: Unable to
>>>>> connect: Connection refused
>>>>>
>>>>> === Could not load default driver and no driver specified in
>>>>> config file. Exiting.
>>>>>
>>>>> Is there a simple way to allow playing sounds in this context?
>>>>>
>>>>> TIA
>>>>
>>>> Received a few replies that suggest it is not trivial to do so.
>>>> Some think it is also unwise.
>>>>
>>>> My current solution is to run the affected script as my non-root
>>>> user and in it run some parts with sudo
>>>> (set up to run without a sudo password to avoid script interruption).
>>>>
>>>> BTW: I did try to use su/sudo back to my user, to run from inside
>>>> the script (which is running as root) but it still fails.
>>>>
>>>
>>> Hi Eyal,
>>>
>>> Not what you asked BUT WHEN DOES THAT STOP ME!!!
>>> <maniacal laughter>
>>>
>>> If you are already running as root, use "su" to
>>> run your command as a user:
>>>
>>> su USER -c "command"
>>>
>>> for example:
>>> su eyal -c "ogg123 -q /audio/ogg/beginning.ogg"
>>>
>>> Because you are already running as root, you
>>> won't be prompted for USER's password.
>>>
>>> You have to use quotes around the command. Use
>>> single quotes if double quotes are used in the command.
>>>
>>> -T
>>
>> Tried it and this does not work for me. Does it work for you?
>
> Something is funny going on. It does work for me:
>
> $ su
> Password:
>
> [root@rn6 Misc]# whoami
> root
>
> [root@rn6 Misc]# su todd -c "ogg123 -q Wagner\ al\ piano\ _\ Stefan\
> Mickisch-EpeMHyL-Gio.ogg"
>
> [root@rn6 Misc]#
I can see the difference.
My script suns as root using 'sudo script.sh'
Doing this works:
$ su
# su eyal -c "ogg123 ...
but doing this does not:
$ sudo -i
# su eyal -c "ogg123 ...
nor does this:
$ sudo -i
# sudo -u eyal "ogg123 ...
So 'su' and 'sudo' set up a different context.
My current solution, as I said before, is to run the script directly and
use 'sudo' only where it is needed.
Hi Eyal,
I hate the sudo command. I never use it.
Try running your script with su instead:
su root -c "script"
-T