#!/bin/bash source /home/apu/testbed_files/apu-tb-opt/scripts/mesh/node_addresses.sh find_key_for_mac() { declare -n list=$1 #nameref for associateve array local mac=$2 for key in "${!list[@]}"; do if [[ "${list[$key]}" == "$mac" ]]; then echo "$key" return fi done echo "Unknown" } # List of nodes to connect to start_node=0 stop_node=24 NODE_LIST=$(seq $start_node 1 $stop_node) USER="root" OUTPUT_FILE="link_info.txt" # Function to extract MAC addresses and signal strengths extract_info() { if [[ $1 -lt 10 ]];then current=0$1 else current=$1 fi local interface=$2 ssh -o StrictHostKeyChecking=no "$USER"@"apu$current" "iw dev $interface station dump" | awk -v node="apu$current" -v iface="$interface" ' /Station/ {link_mac=$2} /signal avg:/ {signal=$3} /mesh plink:/ {state=$3; print node " | " iface " | " link_mac " | " signal " | " state} ' } > "$OUTPUT_FILE" # Loop through each node and interface, extracting information for node in $NODE_LIST; do for iface in "mesh0" "mesh1"; do # cnt_estab=0 # cnt_blocked=0 temp_file=$(mktemp) extract_info "$node" "$iface" >> "$temp_file" # echo "Data collected in temp file for $node and $iface:" # cat "$temp_file" # Process the output file to replace node MAC addresses with node identifiers sorted_file=$(mktemp) while IFS=" | " read -r node_name mesh_link link_mac signal; do if [[ "$mesh_link" == "mesh0" ]]; then link_key=$(find_key_for_mac "phy0MAC" "$link_mac") else link_key=$(find_key_for_mac "phy1MAC" "$link_mac") fi if [[ "$link_key" == "Unknown" ]]; then link_key=$link_mac fi echo "$node_name | $mesh_link | $link_key | $signal" # >> "$temp_file" done < "$temp_file" | sort -t '|' -k4,4nr > "$sorted_file" # echo "Data after processing and sorting:" # cat "$sorted_file" # Append sorted file to the final output file cat "$sorted_file" >> "$OUTPUT_FILE" echo " " >> "$OUTPUT_FILE" # Clean up rm "$temp_file" "$sorted_file" done echo "-------------------------------------" >> "$OUTPUT_FILE" echo " " >> "$OUTPUT_FILE" done echo "Information saved to $OUTPUT_FILE"