What's new

Run Script When AiMesh Node Is Running

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

HarryMuscle

Senior Member
Is it possible to run a script on the main router when a specific AiMesh node is up and running as a node? Alternately what I'm trying to do could also work if it's possible to run a script when an AiMesh node is initially setup/connected to the main router.

Thanks,
Harry
 
Yes.

Alternately, no.

:D
 
Sorry, not a script writer.
 
I have scripts, many of us do, running on the router running with Merlin. Some of us, running Merlin on the mesh node(s) have scripts running on the node as well. But they run independently of each other. I don't believe there is a trigger that can be used in a script on the router to launch/trigger an action when a mesh node starts up.

Though, dumping NVRAM I did find these;
asus_device_list=<3>RT-AX88U>192.168.1.1>24:4B:FE:09:C9:A0>0>(Redacted SSID)>255.255.255.0>1<3>RT-AX86U>192.168.1.161>FC:34:97:38:68:18>0>(Redatcted SSID)>255.255.255.0>2<3>RT-AX86U>192.168.1.187>FC:34:97:38:5A:38>0>(Redacted SSID)>255.255.255.0>2
cfg_device_list=<RT-AX88U>192.168.1.1>24:4B:FE:09:C9:A0>1<RT-AX86U>192.168.1.161>FC:34:97:38:68:18>0<RT-AX86U>192.168.1.187>FC:34:97:38:5A:38>0

Note: the MAC Addr's are the Ethernet (wired) Backhaul/Fronthaul (2x) of the AX88/AX86x2

Though as AiMesh is closed source I don't know how or when these are populated but presumeably you could parse through it. My guess is that when a node is added/discovered is when its added to this list but not when it comes up and and is running, it's closed source so anyone's guess. But this might explain why as I played with ASUS/ version of Merlin why adding the Mesh nodes back in was so easy, who knows. Of course if there was a script on the router that could receive a trigger from a script on a node that runs at start up. Then maybe, but beyond my skill set.
 
An indication of what's desired would likely pull more of us who live to script out of the woodwork.
 
An indication of what's desired would likely pull more of us who live to script out of the woodwork.
There are several NVRAM values I need to set on a node that aren't automatically synced so I was hoping to run a script on the main router that will SSH into a node to make these changes via nvram commands. The idea is to automate this for quick deployment.
 
I'm thinking put the "nvram set ..." commands in a text file followed by the line "nvram commit", and any lines containing "service restart_<whatever>" as required.

scp the file to node:/tmp/<filename>

ssh into node and enter ". /tmp/<filename>"

If running Merlin on the node you could have that file being sourced as the final thing automatically occuring at boot if the desired changes don't survive subsequent reboot otherwise.

Might could make it an executable shell script and declare it as the command to run at ssh login (after getting it there first). Would maybe save you an extra ^d if so.

I don't think I'd waste the time trying to completely-automate the process. You'd have to do it hundreds of times to recoup the investment by the mere moments it takes to do it manually.
 
Last edited:
There are no events there that can be used to trigger.

But there are two ways to achieve what you want:

One of them is to write a script that constantly polls, maybe ping, and runs the script when a node is detected. This method consumes a lot of resources, but it is reliable.

Another way is to run a trigger script on the node router. When the node starts, the script logs into the main router through ssh from the node, and then fetches the changes on the main router.
 
Is it possible to run a script on the main router when a specific AiMesh node is up and running as a node? Alternately what I'm trying to do could also work if it's possible to run a script when an AiMesh node is initially setup/connected to the main router.

Thanks,
Harry
You could create a script that runs on a cron job looking for the IP Address of the Node (Use ARP table looking for MAC Address) and if it is pingable to do execute whatever command(s) you have in mind. I have a similar script for when my printer comes up on my Guest Network.
 
Here's my final script that seems to work pretty well. Hopefully it can prove useful to others. It's two scripts actually, one that checks if nodes are available and running and a second script that gets run on the nodes via the main script to update settings, etc. It was cleaner to use two scripts instead of jamming everything into one.

Code:
#!/bin/bash

# Get the MAC addresses of the mesh nodes and loop through them
nvram get cfg_device_list | \
  grep -E -i -o "[0-9A-F]{2}:[0-9A-F]{2}:[0-9A-F]{2}:[0-9A-F]{2}:[0-9A-F]{2}:[0-9A-F]{2}" | \
  while IFS="" read -r mac
do
  # Update the log
  logger -t "node-update" "Found node with MAC address $mac"

  # Get the IP address for the node's MAC address from the ARP table filtering out any addresses
  #   with a flag of 0x0
  logger -t "node-update" "Finding node IP address ..."
  ip="$(grep -F -i "$mac" /proc/net/arp | awk -F ' ' '{if ($3 != "0x0") {print $1}}')"
  if [[ "$ip" != "" ]]
  then
    # Ping the node once
    logger -t "node-update" "Pinging node ..."
    ping -c 1 -q "$ip" &> /dev/null
    if [[ $? == 0 ]]
    then
      # Log into the node and run the node script located in the same directory as this script
      logger -t "node-update" "Logging into node ..."
      DROPBEAR_PASSWORD="$(nvram get ssh_password)" ssh -l "$(nvram get ssh_username)" -q -y -y \
        "$ip" "bash -s" < "${0%/*}/node-update-node-script" &> /dev/null
      if [[ $? == 0 ]]
      then
        # Update the log
        logger -t "node-update" "Node settings updated"
      else
        # Update the log
        logger -t "node-update" "Unable to log into node"
      fi
    else
      # Update the log
      logger -t "node-update" "Node did not respond to ping"
    fi
  else
    # Update the log
    logger -t "node-update" "No active IP address found"
  fi
done

Since it's currently not possible to retrieve the passwords saved by the router in a script, this script depends on the password being saved to an extra NVRAM value called ssh_password (it can be whatever you want it to be as long as the script is updated accordingly). I also used a ssh_username value to store the SSH username, although this should technically be the same as the GUI username which is stored in http_username I believe.

The node-update-node-script referenced in the script above needs to be in the same directory as the main script and can contain whatever you want to run on the nodes.

Hope someone finds this useful.

Harry
 

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