In my script I want to open a specific (device driver) file as FD 3.
exec 3<
works fine for this in regular cases.
However the device driver file is only readable as root, so I'm looking for a way to open the FD as root using sudo.
-> How can I open a file (descriptor) with sudo rights?
Unfortunately I have to keep the file open for the runtime of the script, so tricks like piping in or out do not work. Also I don't want to run the whole script under sudo rights.
If sudo + exec is not possible at all, an alternative solution is that I could call a program, in background like sudo tail -f
-- but this poses another set of problems:
- how to determine whether the program call was successful
- how to get error messages if the call was not successful
- how to "kill" the program at the end of execution.
EDIT: To clarify what I want to achieve:
- open /dev/tpm0 which requires root permissions
- execute my commands with user permissions
- close /dev/tpm0
The reason behind this is that opening /dev/tpm0 blocks other commands from accessing the tpm which is critical in my situation.
Thanks for your help