What's new

Shell script to add mac filters. Help?

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

StoneGiraffe

Occasional Visitor
Disclaimer - I'm not even a linux newbie, I'm a straight up idiot.

I'm trying to write a script so I can more easily add mac filters via ssh. Basically I'm trying to read the old values out, add a new filter, then set.

So far I'm here and it's clearly not working.

nvram set wl0_maclist=\"`nvram get wl0_maclist` $1\"
nvram set wl0_maclist_x=\"`nvram get wl0_maclist_x`\<$1\"
nvram set wl1_maclist=\"`nvram get wl1_maclist` $1\"
nvram set wl1_maclist_x=\"`nvram get wl1_maclist_x`\<$1\"


Also, if I screw up my nvram and I don't want to commit, how do I roll back?

(Incidentally, only reason I want to do this is that the 2.4 and 5Ghz filters are separate again - I was so happy when they were merged in a previous firmware. Good things don't last forever I guess)
 
Ok, I updated my script and it looks like it works. My previous mistake was escaping the double quotes.

Last question though - after committing my changes to nvram how the heck do I get them to take from the shell without rebooting? I can't seem to find any doc that lets me bounce the network only.

Any hints?

My hack updated script looks like this incidentally:

Code:
#!/bin/sh
mac=`echo "$1" | sed -e 'y/abcdef/ABCDEF/'`
if ! echo "$mac" | grep -q '^\([A-F0-9]\{2\}:\)\{5\}[A-F0-9]\{2\}$'; then
    echo Not a mac address
    exit 1
fi

echo adding mac: $mac

list=`nvram get wl0_maclist`
list_x=`nvram get wl0_maclist_x`
list1=`nvram get wl1_maclist`
list1_x=`nvram get wl1_maclist_x`

if [ ! "$list" == "$list1" ]; then
    echo wl0_maclist and wl1_maclist are out of sync
    echo wl0_maclist "$list"
    echo wl1_maclist "$list1"
    exit 1
fi
if [ ! "$list_x" == "$list1_x" ]; then
    echo wl0_maclist_x and wl1_maclist_x are out of sync
    echo wl0_maclist_x "$list_x"
    echo wl1_maclist_x "$list1_x"
    exit 1
fi

list="$list $mac"
list_x="$list_x<$mac"

if ! echo "$list" | grep -q '^\(\([A-F0-9]\{2\}:\)\{5\}[A-F0-9]\{2\} \)*\(\([A-F0-9]\{2\}:\)\{5\}[A-F0-9]\{2\}\)$'; then
    echo maclist format is invalid:
    echo "$list"
    exit 1
fi
if ! echo "$list_x" | grep -q '^\([\<]\([A-F0-9]\{2\}:\)\{5\}[A-F0-9]\{2\}\)\+$'; then
    echo maclist_x format is invalid:
    echo "$list_x"
    exit 1
fi

echo maclists look ok!
nvram set wl0_maclist="$list"
nvram set wl0_maclist_x="$list_x"
nvram set wl1_maclist="$list"
nvram set wl1_maclist_x="$list_x"

nvram commit
 
Last edited:
Code:
service restart_wireless
 
Hello "StoneGiraffe", can you please send me the script or make it available for download ...i have a probleme with copy and paste from code-box...
 

Similar threads

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top