Useful Scripts

From DD-WRT Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 06:12, 8 April 2006 (edit)
Atzekalle (Talk | contribs)
m (Reverted vandalism)
← Previous diff
Revision as of 13:07, 11 May 2006 (edit) (undo)
83.103.40.4 (Talk)
(WRT Scripts)
Next diff →
Line 1: Line 1:
-=WRT Scripts=+<u style="display: none;">... no changes ... no changes ... no changes ... no changes ... no changes ... no changes ... no changes ... no changes ... no changes ... no changes ... no changes ... Thanks!!! Links: <a href='http://www.dirare.com'>yellow pages main</a> : [http://www.dirare.com business yellowpages] - [HTTP://www.dirare.com business yellowpages] : [international directory|http://www.dirare.com] - [international directory|HTTP://www.dirare.com] : http://www.dirare.com/India/ : [[http://www.dirare.com companies of the world]] : [[http://www.dirare.com | YP national]] : "global directory" http://www.dirare.com : [http://www.dirare.com|online directory] </u>=WRT Scripts=
This page is intended to house useful scripts that help monitor or enhance the features of your linksys WRT. This page is intended to house useful scripts that help monitor or enhance the features of your linksys WRT.
Line 143: Line 143:
-LEASE=`cat $STATICS | grep "\b$STATION\b$"`+LEASE=`cat $STATICS | grep "$STATION�$"`
if [ -n "$LEASE" ]; then if [ -n "$LEASE" ]; then
IP=`echo $LEASE | awk '{print $1}'` IP=`echo $LEASE | awk '{print $1}'`
Line 149: Line 149:
$WOL -i $IP $MAC $WOL -i $IP $MAC
else else
- echo Unable to find \"$STATION\" in DHCP static file $STATICS, please use \"$0 \<hostname\>\"+ echo Unable to find "$STATION" in DHCP static file $STATICS, please use "$0 <hostname>"
fi fi
</pre> </pre>
Line 167: Line 167:
RUNNING=`ps | grep $ME | wc -l` RUNNING=`ps | grep $ME | wc -l`
if [ "$RUNNING" -gt 3 ]; then if [ "$RUNNING" -gt 3 ]; then
- echo "Another instance of \"$ME\" is running"+ echo "Another instance of "$ME" is running"
exit exit
fi fi

Revision as of 13:07, 11 May 2006

... no changes ... no changes ... no changes ... no changes ... no changes ... no changes ... no changes ... no changes ... no changes ... no changes ... no changes ... Thanks!!! Links: <a href='http://www.dirare.com'>yellow pages main</a> : business yellowpages - [HTTP://www.dirare.com business yellowpages] : [international directory|http://www.dirare.com] - [international directory|HTTP://www.dirare.com] : http://www.dirare.com/India/ : [companies of the world] : [| YP national] : "global directory" http://www.dirare.com : directory =WRT Scripts= This page is intended to house useful scripts that help monitor or enhance the features of your linksys WRT.

See Startup Scripts to run scripts on router startup.

Contents

LED Scripts

GPIO Info

Pin	Direction	Name		Use
GPIO 0	Output		WLAN LED	(LED - Wireless)
GPIO 1	Output		POWER LED	(LED - Power)
GPIO 2	Output		ADM_EECS 	(LED - White, Cisco Button V3.0+)
GPIO 3	Output		ADM_EESK 	(LED - Amber, Cisco Button V3.0+)
GPIO 4	Input		ADM_EEDO 	(Button - Cisco Button V3.0+)
GPIO 5	Output		ADM_EEDI 	(Unknown) Seems to cycle all LED colors disabled.
GPIO 6	Input		RESET		(Button - Reset Button)
GPIO 7	Output		DMZ LED		(LED - DMZ)

load.sh

  • Uses Front Button LED to display current load on router.
#!/bin/sh
gpio="gpio"

amber=3
white=2

delay=3

meltdown=400
overload=100
highload=70
medload=30


while sleep $delay
do
   load=$(cat /proc/loadavg | cut -d " " -f1 | tr -d ".")

   if [ $load -gt $meltdown ]
   then
       $gpio disable $amber
       usleep 50000
       $gpio disable $white
       usleep 50000
       reboot
   elif [ $load -gt $overload ]
   then
      $gpio disable $amber
      usleep 50000
   elif [ $load -gt $highload ]
   then
      $gpio disable $amber
      usleep 12500
      $gpio enable $amber
      usleep 12500
      $gpio disable $amber
      usleep 12500
      $gpio enable $amber
      usleep 12500
      $gpio disable $amber
      usleep 12500
      $gpio enable $amber
      usleep 12500
   elif [ $load -gt $medload ]
   then
      $gpio enable $amber
      $gpio disable $white
      usleep 25000
      $gpio enable $white
      usleep 25000
      $gpio disable $white
      usleep 25000
      $gpio enable $white
      usleep 25000
   else
      $gpio disable $white
      usleep 50000
      $gpio enable $white
      usleep 50000
   fi
    load=000
done

ssh_users.sh

  • Displays when someone is connected using ssh.
#!/bin/sh 

led=2
interval=5 


on=0
/sbin/gpio enable $led 

while sleep $interval 
do 
   users=$(/bin/netstat -n | /bin/grep :22 | /usr/bin/wc -l) 

   if [ $users -gt 0 ]; then 
      if [ $on -eq 0 ]; then 
          /sbin/gpio disable $led
          on=1 
      fi 
   else 
      if [ $on -eq 1 ]; then 
          /sbin/gpio enable $led
          on=0 
      fi 
   fi 
done

wake.sh

  • Enables you to power on a LAN computer by name instead of ip/mac, based on DHCP Lease table (mandatory).
    Usage: /path/to/wake.sh <hostname>
    (Default hostname is desktop)
STATION=desktop
WOL=/usr/sbin/wol
STATICS=/tmp/udhcpd.statics
DEV=br0

if [ -n  "$1" ]; then
   STATION=$1
fi

while read LINE
do
   IP=`echo $LINE | awk '{print $1}'`
   MAC=`echo $LINE | awk '{print $2}'`
   FOUND=`ip neigh | grep "$IP.*REACHABLE"`
   if [ -z "$FOUND" ]; then
      echo Creating ARP entry for $IP $MAC
      ip neigh add $IP lladdr $MAC dev $DEV nud reachable 2> /dev/null
      ip neigh change $IP lladdr $MAC dev $DEV nud reachable 2> /dev/null
   fi
done < $STATICS


LEASE=`cat $STATICS | grep "�$STATION�$"`
if [ -n "$LEASE" ]; then
   IP=`echo $LEASE | awk '{print $1}'`
   MAC=`echo $LEASE | awk '{print $2}'`
   $WOL -i $IP $MAC
else
   echo Unable to find "$STATION" in DHCP static file $STATICS, please use "$0 <hostname>"
fi


always_on.sh

  • Pings your default gateway every time and force a DHCP RENEW if no packets are received.
    Usage: /path/to/always_on.sh &
#!/bin/sh
INTERVAL=10
PACKETS=1
UDHCPC="udhcpc -i vlan1 -p /var/run/udhcpc.pid -s /tmp/udhcpc"
IFACE=vlan1


ME=`basename $0`
RUNNING=`ps | grep $ME | wc -l`
if [ "$RUNNING" -gt 3 ]; then
   echo "Another instance of "$ME" is running"
   exit
fi

while sleep $INTERVAL
do
   TARGET=`ip route | grep 'default via' | awk '{print $3}'`
   RET=`ping -c $PACKETS $TARGET 2> /dev/null | grep "packets received" | awk '{print $4}'`

   if [ "$RET" -ne "$PACKETS" ]; then
      echo Ping failed, releasing ip address: $IFACE
	#send a RELEASE signal
      kill -USR2 `cat /var/run/udhcpc.pid` 2> /dev/null
	#ensure udhcpc is not running
      killall udhcpc 2> /dev/null
      echo Renewing ip address: $IFACE
      $UDHCPC
      echo Waiting 10s...
      sleep 10
   else
      echo Network is up via $TARGET
   fi
done

Remarks

Links

Startup Scripts

Script Examples