What's new

GREP commnad Reading through file Question

  • 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!

notchy

New Around Here
I have a need to read through the client list on my asus router RT-AC66U_B1 with Merlin Firmware Version:384.10_2

and if I find the MAC address I am searching for in the file location "/tmp/clientlist.json, I will execute a "CURL" command.

What I have, so far is this logic that i copied from another source. It is using the "wl assoclist" but I have a few AP's that my devices can be on and they will not show up with this command. That is why I want to read the "clientlist.json" with the current MAC addresses and if I find it I do some logic.

Code:
#!/bin/sh
# seconds between checks
WATCHDOG_SLEEP_SEC=2
# MAC Address 1
MAC_ADDRESS_1="[38:8B:59:2F:B5:XX]"
# MAC Address 2
MAC_ADDRESS_2="[08:78:08:3C:3E:XX]"
# Vera VSwitch 1 Device ID
VSWITCH_1="[457]"
# Vera VSwitch 2 Device ID
VSWITCH_2="[459]"

#This loop will check if a device is registered on the AP and send the on/off command to vera.

while sleep $WATCHDOG_SLEEP_SEC
do
if wl assoclist | grep -Fq $MAC_ADDRESS_1
then
    #echo Device 1 user is in
    curl "http://192.168.1.XXX:3480/data_request?id=action&output_format=xml&DeviceNum=457&serviceId=urn:upnp-org:serviceId:VSwitch1&action=SetTarget&newTargetValue=1"
else
    #echo Device 1 user is out
    curl "http://192.168.1.XXX:3480/data_request?id=action&output_format=xml&DeviceNum=457&serviceId=urn:upnp-org:serviceId:VSwitch1&action=SetTarget&newTargetValue=0"
fi

if wl assoclist | grep -Fq $MAC_ADDRESS_2
then
    curl "http://192.168.1.XXX:3480/data_request?id=action&output_format=xml&DeviceNum=458&serviceId=urn:upnp-org:serviceId:VSwitch1&action=SetTarget&newTargetValue=1"
else
    curl "http://192.168.1.XXX:3480/data_request?id=action&output_format=xml&DeviceNum=458&serviceId=urn:upnp-org:serviceId:VSwitch1&action=SetTarget&newTargetValue=0"
fi

done
&
 

Sign Up For SNBForums Daily Digest

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