Writing a bash script to turn on and off the USB ports on a raspberry pi 4. Using uhubctl.
#!/bin/bash
# Script to turn on and off power to usb port
# Uses uhubctl
#
time_w=5
#cd uhubctl
uhubctl -a off -l 1-1
#
sleep "$time_w"
#
uhubctl -a on -l 1-1
#
echo "All done"
I can run this sudo uhubctl -a off -l 1-1 from the command line without issue.
But if I run the script with sudo bash USB_Power.sh I get the following error.
!o compatible smart hubs detected at location 1-1
Run with -h to get usage info.
All done
sudo)? Also what happens if you just runsudo USB_Power.sh? Is this the only version of the script on your system? – Nov 25 '20 at 21:02sudoand I also run the script assudoThis is the only version of the script on the system. When I run the command is executes just fine - but when I run it as the script it just doesn't work. – ShekelsBot Nov 25 '20 at 21:54sheither way it wont run. I have been trying to add USB permissions so that I dont have to use sudo - followed the guide still have to use sudo. The command works outside of the script if I use sudo. I am running the command with sudo so permissions shouldn't be an issue. – ShekelsBot Nov 26 '20 at 03:44sudo chmod +x USB_Power.shthen run it as./USB_Power.shandsudo ./USB_Power.sh– Nov 26 '20 at 03:57sudo ./USB_Power.shI get the following errorsudo: unable to execute ./USB_Power.sh: No such file or directory– ShekelsBot Nov 26 '20 at 19:12ls USB*– Nov 26 '20 at 19:25sudo uhubctl -a off -l 1-1? It is still confusing me if it isn't written there. – Ingo Nov 26 '20 at 19:40