EdgeRouter - Run Operational Mode Command from Scripts


Overview


Readers will learn how to run operational mode commands from scripts.

NOTES & REQUIREMENTS: Applicable to the latest EdgeOS firmware on all EdgeRouter models. Please see the Related Articles below for more information. Device used in this article:

Creating a Script


Back to Top

In this example a script is run to clear all the DHCP leases.

CLI: Access the command line interface (CLI). You can do this using the CLI button in the GUI or by using a program such as PuTTY.

1. Log in as the root user.

sudo su

2. Create a basic script using the cat command. 

cat > /config/scripts/cleardhcp 
NOTE: The script is stored in the /config directory to prevent it from being lost during reboots and firmware upgrades.

2. Add the following contents to the script.

#!/bin/vbash
/opt/vyatta/bin/vyatta-op-cmd-wrapper clear dhcp leases

echo $(date +"%h %e %T") 'dhcpd: DHCP leases cleared' >> /var/log/messages

exit 0

NOTE: The vyatta-op-cmd-wrapper is needed to run the script. The echo command is optional and is mainly used to log that the script was run.

3. Use CTRL+D to exit out and save the script.

4. Modify the permissions to allow the script to execute.

chmod +x /config/scripts/cleardhcp 

5. Exit back to the EdgeOS command line.

exit

6. Run the script.

sudo /config/scripts/cleardhcp


Related Articles


Back to Top

EdgeRouter - Configuration and Operational Mode

Intro to Networking - How to Establish a Connection Using SSH