EdgeRouter - Add commands to EdgeOS


You can add simple commands to EdgeOS. For example, reset is a top-level EdgeOS command that is not available in the CLI.


For this example, we'll add a command to reset the console.

  1. When first running the reset command, a single option exists.

    1. ubnt@RTR:~$ reset ?
  2. To add commands, it's necessary to become the root user. The sudo command is used to gain root user privileges.

    ubnt@RTR:~$ sudo bash
  3. Now as root user, navigate to the directory with all of the operational mode templates.

    1. root@RTR:/home/ubnt# cd /opt/vyatta/share/vyatta-op/templates
      root@RTR:/opt/vyatta/share/vyatta-op/templates# ls
      add            delete         ping6          reset          terminal
      clear          disconnect     reboot         restart        traceroute
      configure      generate       release        set            traceroute6
      connect        initial-setup  remove         show           undebug
      copy           no             rename         shutdown       update
      debug          ping           renew          telnet
  4. Go to the reset directory and create a reset sub-command.

    root@RTR:/opt/vyatta/share/vyatta-op/templates# cd reset
    root@RTR:/opt/vyatta/share/vyatta-op/templates/reset# ls
    node.def  openvpn
  5. Use the mkdir command to create a directory called console.

    root@RTR:/opt/vyatta/share/vyatta-op/templates/reset# mkdir console
    root@RTR:/opt/vyatta/share/vyatta-op/templates/reset# cd console
  6. While in root, use the cat (concatenate) command to create a file named node.def in the console directory. Add the lines "help..." and "run..." as listed below. Hit enter then press ctrl + c to finish editing the file.

    root@RTR:/opt/vyatta/share/vyatta-op/templates/reset/console# cat > node.def
    help: Reset the console
    run: /usr/bin/reset
  7. Exit out of root and try out the new command:

  8. root@RTR:/opt/vyatta/share/vyatta-op/templates/reset/console# exit
    ubnt@RTR:~$ reset ?        
    console  openvpn  
    ubnt@RTR:~$ reset ?
    Possible completions:
      console       Reset the console
      openvpn       Reset OpenVPN 
    ubnt@RTR:~$ reset console
Powered by Zendesk