tpprynn wrote:I've tried a few combinations, almost blindly:
Code: Select all
root@xxxxx-laptop:/sys/devices/platform/asus_laptop# echo 1 > $WLAN_LED
bash: $WLAN_LED: ambiguous redirect
root@xxxxx-laptop:/sys/devices/platform/asus_laptop# cd /etc/NetworkManager/dispatcher.d
root@xxxxx-laptop:/etc/NetworkManager/dispatcher.d# echo 1 > $WLAN_LED
bash: $WLAN_LED: ambiguous redirect
root@xxxxx-laptop:/etc/NetworkManager/dispatcher.d#
Code: Select all
xxxxx@xxxxx-laptop:~$ sudo su
[sudo] password for xxxxx:
root@xxxxx-laptop:/home/xxxxx# cd /sys/devices/platform/asus_laptop
root@xxxxx-laptop:/sys/devices/platform/asus_laptop# echo 1 > wlan
root@xxxxx-laptop:/sys/devices/platform/asus_laptop# echo 0 > wlan
When using the phrase echo 1 [or 0] > wlan the LED changes state as hoped. But when the string $WLAN_LED is used as defined in the toshleds.sh script as advised by a programmer this ambiguous redirect message comes up and the LED state does not change. I don't have the knowledge to know if the routine should still work in the context of the script regardless of whether the lines work in isolation. I've not done any scripting before - I did a bit of BASIC programming in the mid-1980s and I've done a bit of gtk theming in the last two years. I don't want to master it but I would like to achieve this goal and I have one idea for something else later. It is fascinating to me but I have other creative outlets and can't really spare the time to learn in great depth.
I imagine I'm still without the line(s) that make the script look for change continually?
Code: Select all
#!/bin/sh
WLAN_LED=/sys/devices/platform/asus_laptop/wlan
while ["$IF" = "wlan1"] && ["$STATUS" = "down"]; then
echo 0 > $WLAN_LED
fi
while ["$IF" = "wlan1"] && ["$STATUS" = "up"]; then
echo 1 > $WLAN_LED
fi
Is chmod +x [filename] enough? It shouldn't be chmod u+x as I've seen elsewhere?
Could this script only work in NetworkManager/dispatcher.d?
Thanks.
Hya tpprynn, couldn't let this topic go
There's a lot of questions in here, may not cover them all, but I'll try at the hand of an example. Mind you, there's more than 1 way to do this, but I'll stick to this one
I am gonna use the bash-shell myself, as overhere /bin/sh is redirected to dash, of which I didn't even know it excisted or how it will react to my script.
for the echo's I've put the target between quotes, and variables between { and } as that has solved quite some issues for me over the past years.
I'll put my script first, and discuss it after.
Code: Select all
#!/bin/bash
## File I will use.
WLAN_LED=/sys/devices/platform/asus_laptop/wlan
## Now, we need to create a loop that will continuously check the status of the interface, and to minimiza I/O,
## load, modifications, only alter the file if the state changes.
while true
do
case ${IF} in
wlan1) if [ "${STATUS}" = "down"]
then
if [ `cat ${WLAN_LED}` = "1" ]
then
echo 0 > "${WLAN_LED}"
fi
elif [ `cat ${WLAN_LED}` = "0" ]
then
echo 1 > "${WLAN_LED}"
fi
;;
*) echo "Caught wrong interface. Exiting."
exit 2
;;
esac
done
Breaking it down step by step:
line 1: Choose bash-shell
line 4: declare variable (file that needs to be edited)
line 9: continuous loop starts
line 11: compare content of variable IF to a list consisting of text "wlan1" and "everything else".
line 12: IF matched to "wlan1", compare the variable STATUS to the word "down". if it matches, go to line 14, else go to line 18.
line 14: We're here, so status of wifi is "down" and LED needs to be turned of. Compare content of file to text "1". If it's a match, go to line 16. If it's not a match, it means it's already turned off so we're done: pass fi twice, "exit" the entered match using ";;", pass esac, and go to line 27.
line 16: Put a 0 in the file to turn off the LED, pass fi twice, "exit" the entered match using ";;", pass esac, and go to line 27.
line 18: We're here, so we know status of wifi is "up" and LED needs to be turned on. Compare content of file to text "0". If it's a match, go to line 20. If it's not, it means it's already turned on so we're done: pass fi, "exit" the entered match using ";;", pass esac, and go to line 27.
line 20: Put a 1 in the file to turn on the LED, pass fi, "exit" the entered match using ";;", pass esac, and go to line 27.
line 22: ";;" means last line of this match.
line 23: IF did not match to "wlan1", so we tell the user that we were not succesfull.
line 24: exit the script with status 2.
line 25: ";;" means last line of this match.
line 26: "esac" means last line of this case.
line 27: we're done for now. Test the while-statement again. If it's true, go to line 9. If it's not true, break and go to next line.
Now, for some of the questions you asked:
Putting the redirect-target between quotes should give you a better error, if you get one at all.
chmod +x works, albeit overkill as it grants everyone on the system executing-rights. chmod u+x limits this to the owner of the file.
The script should be able to work from any location, as long as you have access to the script and the file you want to alter.
I hope I've been of help and at least helped out with understanding shell-scripting. It's so much fun!
Cheers,
Anakin
P.S. I saw the forum-software plays a bit with the indenting, I've put the script in as an attachment as well.