Location and Address Automatically

Location and Address Automatically

Introduction:
Often when the Nodegrid comes up. it would be great if the NG knows where it is automatically. currently, the user would have to enter the address and the coordinates manually in the System::Preferences.

Requirement:
Warning
The Nodegrid needs to be plugged into an ethernet IP network with internet accessible

Steps:
This script will automatically run when the Nodegrid boots up.

1. In the Nodegrid console log in as root "shell sudo su -"
2. Copy the attached script "getNGLoc.sh" to the Nodegrid /etc/init.d folder
3. Go to /etc/init.d folder and change script to be executable "chmod +x getNGLoc.sh"
4. Go to /etc/rc5.d folder
5. Set a soft link to the script "ln -s /etc/init.d/getNGLoc.sh S99getNGLoc.sh"

The system will now run this script when the Nodegrid boots up to update the System::Preference address and coordinates

getNGLoc.sh
  1. #!/bin/bash
  2. # wait for the system to comes up first before execution sleep 60 Seconds
  3. sleep 60
  4. myLocData=$(curl http://ip-api.com/json?fields=lat,lon)
  5. longitude=$(echo "$myLocData" | jq -r .lon)
  6. latitude=$(echo "$myLocData" | jq -r .lat)
  7. coord="$latitude,$longitude"

  8. # Fetch geolocation data using ipinfo.io
  9. location_data=$(curl -s ipinfo.io)
  10. # Extract city and region (state) from the JSON response
  11. city=$(echo $location_data | jq -r '.city')
  12. state=$(echo $location_data | jq -r '.region')
  13. address="$city,$state"

  14. tmpFile="/home/admin/outLoc.cli"
  15. echo "cd /settings/system_preferences/" > $tmpFile
  16. echo "set address_location=$address" >> $tmpFile
  17. echo "set coordinates=$coord" >> $tmpFile
  18. echo "commit" >> $tmpFile
  19. su - admin -c "cli -f $tmpFile"
  20. rm $tmpFile

    • Related Articles

    • MIB files location in NodeGrid

      Introduction: A management information base (MIB) is a database used for managing the entities in a communication network. Most often associated with the Simple Network Management Protocol (SNMP). MIB file are found in NodeGrid by default at ...
    • Setting a firewall rule to block a single IP address

      Nodegrid can act as a firewall to filter traffic. It has six build in chains ( three for ipv4 and three for ipv6 ) - INPUT, OUTPUT and FORWARD Default policy can be assigned for each chain. For each chain, rules can be added deleted and modified. ...
    • Creating a New Firewall rule to block an Ip address or a network

      There are six default chains to configure firewall rules. Three for IPv4 and three for IPv6.  These chains are input , output and forward packets. One can make additional user chain if required. For each chain, policy can be created. Configuration ...
    • PaloAlto VM installation in the Nodegrid

      Why have a PaloAlto VM in the Nodegrid Having a PaloAlto VM running in the Nodegrid provides a secured OOB network.  Stopping the back-door access into the production network.  Not only securing the OOB network, The PaloAlto can also secured the ...
    • Setting a Firewall Rule to Block a Single IP Address