I wrote this script to reset a USB controller:

echo -n '1-2' | tee /sys/bus/usb/drivers/usb/unbind
sleep 0.5
echo -n '1-2' | tee /sys/bus/usb/drivers/usb/bind

I can then run it like so:

q201:/data # sh foobar.sh
1-21-2q201:/data #

But I cannot run it like this:

q201:/data # su -c "sh /data/foobar.sh"
tee: /sys/bus/usb/drivers/usb/unbind: Permission denied
1-2tee: /sys/bus/usb/drivers/usb/bind: Permission denied
1|q201:/data #

It only works when I am connected to SSHDroid on my rooted device, other apps such as Kernel Adiutor, Script Manager fail to run the script and get the same permission denied error that I get when I try to run it with su.

The su binary that came with my android device does not prompt to grant permission. It just gives it to any apps that ask.

I just want this script to run via other apps, and/or on startup.


The issue is with SELinux, and upon further digging, it seems I had to adjust the permissions of these files to make this work. I don't really understand it, but it seems to work.

chmod 644 /sys/bus/usb/drivers/usb/unbind
chmod 644 /sys/bus/usb/drivers/usb/bind

echo -n '1-2' | tee /sys/bus/usb/drivers/usb/unbind
sleep 0.5
echo -n '1-2' | tee /sys/bus/usb/drivers/usb/bind

chmod 200 /sys/bus/usb/drivers/usb/unbind
chmod 200 /sys/bus/usb/drivers/usb/bind

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.