EdgeRouter Bash Scripting - cfloquetprojects/homelab GitHub Wiki
Prerequisites (Pre-Flight Check):
- Device should be networked and interactable through SSH using a client of your choice.
- Be sure you are able to transfer the bash script I've written to the EdgeRouter using scp from the command line (or a GUI tool like WinSCP)
Creating Bash Script to Automate:
- I have uploaded a finalized AutoStart.bash script to the code section of this github, which you are free to use on your own or follow along.
- EdgeRouter allows us to create bash scripts to interact with the shell by starting any
.bash
file with the following:
#!/bin/vbash
run=/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper
- Now that we have our run command defined, we can use it to run our other commands in the future, shown below:
$run begin
$run show version
- If we
chmod +x kickoff.bash
will allows it to be executed, we can run the script and see that it prints out the version of the OS.
cfloquet@edge01:~$ ./kickoff.bash
Version: v2.0.9-hotfix.1
Build ID: 5371034
Build on: 01/22/21 10:14
Copyright: 2012-2020 Ubiquiti Networks, Inc.
HW model: EdgeRouter X 5-Port
HW S/N: 18E829AFBD9C
Uptime: 19:57:39 up 41 min, 1 user, load average: 1.00, 1.03, 1.00
Scripting Basic Router Setup:
- Now that we have the basic syntax for automating config commands, let's use that to set a new hostname:
#!/bin/vbash
run=/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper
echo "[+] Starting EdgeRouter Automated Kickoff..."
echo " - Please enter your desired system hostname: "
read hostName
$run begin
$run set system host-name $hostName
$run commit