

ls -l <filename>



oskar@oskar-Aspire-5741G ~ $ ls -l /sys/devices/system/
total 0
drwxr-xr-x 3 root root 0 2011-11-08 02:08 clocksource
drwxr-xr-x 9 root root 0 2011-11-07 13:01 cpu
etc...
-rwxr-xr-x 1 root root 209 and the date and time.
echo 1 > $WLAN_LEDecho $STATUS


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#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
#!/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
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.
#!/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


sudo bash -x /location/of/your/script.sh


- I made a script with variables IF and STATUS, but never "declared" them, so where do they come from and how are they filled?






echo "1" > /sys/devices/platform/asus_laptop/wlan # turn on the LED
echo "0" > /sys/devices/platform/asus_laptop/wlan # turn off the LED
Linuxtraveler wrote:Check /sys/class/net/eth0/operstate and other files in this directory.
cat /sys/class/net/wlan1/operstate#!/bin/sh
# Changes the on/off state of the wireless LED depending
# on the operational status of the wireless device.
INTERFACE="wlan1" # Change this where applicable
STATE_FILE="/sys/class/net/$INTERFACE/operstate"
LED_FILE="/sys/devices/platform/asus_laptop/wlan"
LED_STATUS=`cat $LED_FILE` # Check the current state of the LED
# Loop forever
while [ true ]
do
INTERFACE_STATUS=`cat $STATE_FILE` # Is wireless up or down?
if [ "$INTERFACE_STATUS" = "up" ]
then
if [ "$LED_STATUS" -eq "0" ] # Is it necessary to turn on the LED?
then
echo "1" > $LED_FILE # turn on the LED
LED_STATUS="1"
fi
else
if [ "$LED_STATUS" -eq "1" ] # Is it necessary to turn off the LED?
then
echo "0" > $LED_FILE # turn off the LED
LED_STATUS="0"
fi
fi
sleep 2 # Thou shalt not hog thy CPU's cycles!
done
# EOFchmod +x ./asus-led.sh
sudo ./asus-led.shsudo mv ./asus-led.sh /root
sudo chown root:root /root/asus-led.shsudo crontab -u root -e# m h dom mon dow command
@reboot /root/asus-led.sh
Per Ekman wrote:/sys/class/net/eth0/carrier was the perfect answer to this question for me.
cat /sys/class/net/wlan1/carrier#!/bin/sh
# Changes the on/off state of the wireless LED depending
# on the operational status of the wireless device.
INTERFACE="wlan1" # Change this where applicable
CARRIER_FILE="/sys/class/net/$INTERFACE/carrier"
LED_FILE="/sys/devices/platform/asus_laptop/wlan"
LED_STATUS=`cat $LED_FILE` # Check the current state of the LED
while [ true ] # Loop forever
do
# Check current wireless state
CARRIER_STATUS=`cat $CARRIER_FILE`
if [ -z $CARRIER_STATUS ] # Variable might be empty; catch this possibility!
then
CARRIER_STATUS=0
fi
# Is it necessary to update the LED?
if [ $CARRIER_STATUS -ne $LED_STATUS ]
then
echo $CARRIER_STATUS > $LED_FILE
LED_STATUS=$CARRIER_STATUS
fi
sleep 2 # Thou shalt not hog thy CPU's cycles!
done
# EOF



tpprynn wrote:I can't still at present tell a variable from a typical bash command/term...
tpprynn wrote:But if I give up and offer to give up to three English pounds to the charity of your choice and give you all the specifics (although I think I have) maybe you could give me the exact script I need? Unless it turns out that you have and the wlan-/wlan1 mix-up was the problem...
tpprynn wrote:Edit: I had a quick go before going out and it turns the light on but then the light does not respond to the wireless being turned off - the light stays on. This may turn out to be my fault, I'll see later. I ran the 'pimped' script exactly as it is bar the change ot wlan0.


Users browsing this forum: No registered users and 2 guests