I created a python code that requires sudo permission to run. The problem is that its an automated code which will run whenever the computer starts, so is there a way by which I can give it sudo permission only once and will run with sudo permission later without asking for any password?
I've already tried giving it +x permissions (I know that wouldn't work but anyway) by running sudo chmod +x main.py
but that didn't helped
the work my code does is detecting a presence of removable devices(For eg. pendrive) in the computer and prints the filenames that are present in that device. My code prints all the stuff and does well when the device is already connected but if its connected later, it gives a traceback:
Traceback (most recent call last):
File "/home/rapidfire69/RaPiD/coding/Projects/Python/PenDrive_Thief/PenDrive_Thief.py", line 17, in <module>
myFunction()
File "/home/rapidfire69/RaPiD/coding/Projects/Python/PenDrive_Thief/PenDrive_Thief.py", line 7, in myFunction
raw_files = (os.listdir(base_path+devices[0]))
PermissionError: [Errno 13] Permission denied: '/media/username/pendrive'
My OS is Ubuntu 20.04. Python 3
Please help....