LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-21-2016, 07:45 PM   #1
rbees
Member
 
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921

Rep: Reputation: 46
permission issues with alsactl in bash script


I have a script that stores the audio volumes with

Code:
alsactl --file ~/bin/shabbat/data/asound.state store
This script works well on the laptop as a normal user but fails on the desktop as a normal user. Not sure if I were to run it as root, see below.

There is some kind of permissions issue that I have not been able to find.

The same paths and file structures exist on both machines.

Code:
rbees@TVBee:~$ alsactl --file ~/bin/shabbat/data/asound.state store
-bash: alsactl: command not found
so I

Code:
rbees@TVBee:~$ su
Password: 
root@TVBee:/home/rbees# alsactl --file ~/bin/shabbat/data/asound.state store
X11 connection rejected because of wrong authentication.
xcb_connection_has_error() returned true
XDG_RUNTIME_DIR (/run/user/1000) is not owned by us (uid 0), but by uid 1000! (This could e g happen if you try to connect to a non-root PulseAudio as a root user, over the native protocol. Don't do that.)
alsactl: save_state:1626: Cannot open /root/bin/shabbat/data/asound.state for writing: No such file or directory
opps, wrong path, so I fixed that and

Code:
root@TVBee:/home/rbees# alsactl --file home/rbees/bin/shabbat/data/asound.state store
X11 connection rejected because of wrong authentication.
xcb_connection_has_error() returned true
XDG_RUNTIME_DIR (/run/user/1000) is not owned by us (uid 0), but by uid 1000! (This could e g happen if you try to connect to a non-root PulseAudio as a root user, over the native protocol. Don't do that.)
alsactl: save_state:1626: Cannot open home/rbees/bin/shabbat/data/asound.state for writing: No such file or directory
but the file is there.

Code:
root@TVBee:/home/rbees# cd /home/rbees/bin/shabbat/data

root@TVBee:/home/rbees/bin/shabbat/data# ls
.........
asound.state
.........
Needless to say i really don't understand what is NOT happening.

I have goggled for the correct permissions for alsactl but so far no joy.

The user is a member of the audio group

[CODE]audio:x:29:rbees,mythtv,pulse

The only differences in the user permissions are

Code:
(desktop)lpadmin:x:111:rbees

(laptop)dialout:*:20:root,kingbee,smsd,gsmsms
floppy:x:25:kingbee
vboxusers:*:127:kingbee
None of which seem to be something that should interfere with my script.
 
Old 08-22-2016, 01:50 AM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
which distro?
which version of alsa?
why is this posted in non-nix???


Quote:
Originally Posted by rbees View Post
I have a script that stores the audio volumes with
why does alsa not store volumes automatically?
it does on my system.

i suspect an xy-problem, so maybe sth else is the REAL problem here?
 
Old 08-22-2016, 04:49 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Code:
rbees@TVBee:~$ alsactl --file ~/bin/shabbat/data/asound.state store
-bash: alsactl: command not found
The above indicates that on this machine alsactl does not exist or cannot be found. So either it is not installed or the user executing the call does not have the path to the executable.
Have you tried to see the output of the following:
Code:
which alsactl
Obviously this needs to be run on the machine with the above error (desktop I believe)
 
Old 08-22-2016, 06:22 AM   #4
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,140

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
You should not store data files in /bin. That directory is for executable programs. Normally, you should keep your data files under your home directory so that you can find them easily in programs or to back up.
 
Old 08-22-2016, 07:33 AM   #5
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Maybe laptop uses plain alsa while desktop uses pulseaudio for sound, there are some differences in control
 
Old 08-22-2016, 06:49 PM   #6
rbees
Member
 
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921

Original Poster
Rep: Reputation: 46
ondoho:
which distro? Debian Testing (Stretch), updated weekly on both machines.
which version of alsa? 1.0.27+1
why is this posted in non-nix??? Because it is a program script issue !!!

grail:
as normal user on the desktop
Code:
rbees@TVBee:~$ which alsactl
You have new mail in /var/mail/rbees
rbees@TVBee:~$
and as root
Code:
root@TVBee:/home/rbees# which alsactl
/usr/sbin/alsactl
root@TVBee:/home/rbees#
and as a normal user on the laptop
Code:
kingbee@BumbleBee:~$ which alsactl
/usr/sbin/alsactl
kingbee@BumbleBee:~$
The desktop I am certain is pristine. The laptop on the other hand has been upgraded through at least 2 versions of testing and maybe three. I am certain that I have done something to the laptop that gave my account more privilege than normal. I just don't know what it was and it would have been a long time ago.

And yes this is the same script that you have been kind enough to help me through.

smallpond: Check the paths I provided again. /home/user/bin/shabbat/data...

keefaz: good thought but both pulseaudio and alsa are installed on both

So following on the notion that I changed something on the laptop I checked the executable and on the laptop /usr/sbin/alsactl is -rwxr-xr-x (0755) Owner:root/root. And on the destop /usr/sbin/alsactl is -rwxr-xr-x (0755) Owner:root/root. So I did not change that. grrr.

Clearly something is different but I have not found it yet. Any other ideas?
 
Old 08-23-2016, 09:07 AM   #7
rbees
Member
 
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921

Original Poster
Rep: Reputation: 46
So just to be sure that the changed permissions were properly applied I rebooted the desktop.

I still get this
Code:
rbees@TVBee:~$ which alsactl
rbees@TVBee:~$ alsactl --file ~/bin/shabbat/data/asound.state store
-bash: alsactl: command not found
rbees@TVBee:~$ sudo alsactl --file /home/rbees/bin/shabbat/data/asound.state store
[sudo] password for rbees: 
X11 connection rejected because of wrong authentication.
xcb_connection_has_error() returned true
rbees@TVBee:~$
What I don't understand is why X11 is even being polled in this case. This is completely a command line thing. The above is via an ssh login. When logged in locally I don't get the X11 error, but it returns nothing either.

It does work locally with sudo after the reboot. But I had logged out and back in before just not a reboot. But it still does not work as a normal user even though that user is a member of the adm group which I thought gave the user certain elevated privileges.

Perhaps I am not understanding the groups correctly.
 
Old 08-23-2016, 09:19 AM   #8
rbees
Member
 
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921

Original Poster
Rep: Reputation: 46
So after looking at the user permissions I think I may have found it. At one time I was trying to set up my laptop to dialout through my cell to my landline to get a low speed Internet connection as we did not have smart phones at the time. It so happens that the dialout group has root and the local user as members.

Not sure why root would need to be a member of any group but...

Would that allow the local user to execute some privileged programs?

Last edited by rbees; 08-23-2016 at 09:39 AM.
 
Old 08-23-2016, 10:10 AM   #9
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Ok, so the issue for rbees user is that /usr/sbin is not in their path and hence the call to which returns nothing and the command errors when called as it cannot be found.

I think the issue for it being run as root is that you already have alsa running in the current x11 environment which is not associated with root but the user rbees and hence when called as root
it is trying to connect to an environment as root, which is not there (this may be wrong so don't quote me )

Try using the full path to the executable and see if that works for rbees user:
Code:
/usr/sbin/alsactl --file ~/bin/shabbat/data/asound.state store
On a side note, whilst the bin directory you are using is local to the user in their home directory, it is still not the correct place to store a data file in the linux way of thinking as bin directories
anywhere on the machine are meant to be used for executable files.
 
Old 08-23-2016, 05:03 PM   #10
rbees
Member
 
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921

Original Poster
Rep: Reputation: 46
Now that you mention it I do remember that I did edit ~/.profile on the laptop and add /usr/sbin to the path for my user account.

So now I need to decide what is the best way to take care of this issue on a larger scale.

1. I could just make a simple readme containing the system changes that need to be made manually so the script will work correctly. And I will have to to some extent because root will be needed to make the changes to the user account and I am not willing to have the script run as root.

2. I could add the path to the dozen or so small scripts that have the volume control feature. Not sure I am interested in the work involved and I would surely miss one or two files that need the edit. Or perhaps edit the .profile with the $PATH changes. But then the user has access to a bunch of executables that they probably should not have access to. In both of these cases the path is then hard coded, not sure I like that.

3. I could write the volume control line so that it dynamically adds the correct path at runtime. Still have to edit a bunch of files that way but at least the script is more cross platform.

4. I could try (and fail) to set it up to take care of it at install time.


Any thoughts?
 
Old 08-23-2016, 07:40 PM   #11
rbees
Member
 
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921

Original Poster
Rep: Reputation: 46
So attempting option 3 I am running into an issue. Big surprise no? Anyway.

I have edited one of the files to contain a dynamic call to alsactl
Code:
#!/bin/bash

fan=$(which alsactl)
STORDIR="${HOME}/bin/shabbat/data"

"$fan --file $STORDIR/asound.state store"
killall -9 mpg123
sleep 10

amixer set Master 70%

mpg123 $STORDIR/bin/shabbat/music/Shabbas.mp3

espeak -s115 "Shabbat is comming,
Shabbat is comming,
Shabbat is comming and it is on it's way,
It will be here in less than 6 days."
sleep 3

"$fan --file $STORDIR/asound.state restore"
sleep 20
~/bin/shabbat/radio
But I keep getting "no such file or directory" on both alsactl lines. Yet if I cat that file at that location it comes up.

I have been doing my test runs with something like
Code:
rbees@TVBee:~$ bin/shabbat/data/havdalah
Which all seams to boil down to, once again, not having /usr/sbin in the users path, which I am trying to avoid so the call to "which alsactl" is failing.

What is the least invasive way to the system to work around this issue? Yet be simple enough that most people would be able to set it up? Even if they don't have root/admin on the machine?

Perhaps a different way of saving the current volume and restoring it is needed. Any idea how that may be done simply?
 
Old 08-23-2016, 11:53 PM   #12
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
As you saw on the previous call to 'which' on the desktop, it returns nothing so your script would of course still fail. The simplest method is just to write the full path at the top and use
as required. The esy why to find all your files to be edited is just use a simple grep recursively, then you could simply feed that into a loop and do a sed to make the changes required.
 
Old 08-24-2016, 02:22 PM   #13
rbees
Member
 
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921

Original Poster
Rep: Reputation: 46
So I ended up putting the whole path in each file.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] STAT issues in bash script; please help! DaemonHunter Programming 7 07-21-2013 01:17 PM
Bash script issues -- halp! danowar Programming 14 02-09-2012 03:37 PM
BASH backup script fails - with permission denied looop Programming 9 01-19-2012 02:45 AM
hotplug & alsactl causing sound card issues halfpower Slackware 3 04-28-2009 07:59 PM
Calling a bash script from PHP - permission denied helsing Linux - Server 3 08-21-2008 07:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration