You are not logged in.
Within a shell script, what an elegant way to check to see if the user invoking the script, has sudo access to specifically /usr/bin/mount and /usr/bin/umount?
I have added this line to /etc/sudoers
foo ALL=(ALL) NOPASSWD: /usr/bin/mount,/usr/bin/umount
What I thought about doing:
`sudo -n mount &>/dev/null` which should return 0 if the user can run it as sudo and `sudo -n umount -V` which also will return 0.
Last edited by graysky (2015-09-01 16:36:50)
CPU-optimized Linux-ck packages @ Repo-ck • AUR packages • Zsh and other configs
Offline
Looks like mount with the options -f and -n, would be a better test of whether the command would actually succeed.
Offline
^ That's better.
--
How about adding -k to prevent a lingering timestamp from influencing the result:
sudo -kn mount &>/dev/null && echo "Can run" || echo "Can't ruN"
Last edited by jsoy9pQbYVNu5nfU (2015-08-30 11:33:58)
Offline
http://udisks.freedesktop.org/docs/latest/
https://wiki.archlinux.org/index.php/Udisks
if present is more elegant than sudo mount
Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest
Offline
Thanks all. I opted for:
sudo -nk mount &>/dev/null
[[ $? -ne 0 ]] && FAILCODE=1
sudo -nk umount -V &>/dev/null
[[ $? -ne 0 ]] && FAILCODE=1
EDIT: I opened a new thread here to solicit feedback from udisks/udisks2 users to achieve this without the bash helper script.
Last edited by graysky (2015-09-18 19:31:13)
CPU-optimized Linux-ck packages @ Repo-ck • AUR packages • Zsh and other configs
Offline