Linux for network engineers lab 9 of 14

Bash for network tasks: loop over hosts and parse output

You turn a morning of manual checks into scripts: a parallel ping sweep, service checks, log statistics, a look at every router over SSH, and a report that cron runs for you.

Run this lab

It needs Lite: its 5 nodes are set to 5 vCPU and 3,072 MB in total. That fits the free demo too.

In your workspace: Shared, then Linux for network engineers guided labs, then 09 - Bash for network tasks - loop over hosts and parse output

Try it free for 30 minutesRun it on Lite from £3 a day

The free demo needs no card and no email. Every lab plan includes every guided lab.

Level
Intermediate
Time
About 75 minutes
Nodes need
5 vCPU, 3,072 MB
Smallest plan
Lite

The scenario

Every morning at Barnsley, somebody pings the depot's kit by hand, logs in to two routers, and skims the firewall log. It takes half an hour and it's always skipped when things are busy, which is when it matters. Automate it on WS, one script at a time. The files you need are already in /root/lab.

DeviceInterfaceAddressRole
WSeth010.9.10.50/24your workstation; bash, ssh, awk and friends
R1, R2Gi0/010.9.10.1, 10.9.10.2 /24routers; user ops, SSH only
H1eth010.9.10.11/24web server on port 80, SSH
H2eth010.9.10.12/24SSH only
printer10.9.10.13switched off, so it never answers
DeviceRunsHow to log in
WSUbuntu 22.04 desktop containerIts console is a remote desktop: root / eve. Open a terminal there.
H1, H2Alpine Linux 3.20root, no password.
R1, R2Cisco IOSv 15.9The console opens at >; enable has no password.

What you’ll practise

  • Loop over files of hosts with while read
  • Run jobs in parallel with & and wait
  • Test TCP services from Bash and use exit codes
  • Parse text with grep, cut, awk, sort and uniq
  • Collect output from routers over SSH keys
  • Schedule a script with cron and allow for its environment

The tasks

  1. Start the Linux nodes
  2. Sweep the network
  3. Check services, not just hosts
  4. Pull facts out of logs
  5. Ask the routers
  6. Put it on a schedule

The Lab Tasks pane has the scenario, these tasks, the checks to run, hints and the full solution.

Topology and devices

The network as it opens in EVE-NG, drawn from the lab’s own canvas, and the image each node runs.

Topology of Bash for network tasks - loop over hosts and parse output5 nodes and 1 network, 5 links. Every link is listed as text below the diagram.WSH1H2R1R2LANGi0/0eth0eth0Gi0/0eth0
5 nodes and 1 network, with the interface names each link uses. On a narrow screen, scroll the diagram sideways.
Nodes in Bash for network tasks: loop over hosts and parse output, with the image each runs and the vCPU and RAM it’s set to
NodeDeviceImage in Add NodeSet to
WSEVE-NG GUI server (Docker)eve-gui-server:latest1 vCPU, 1,024 MB
H1Alpine Linuxclbalpinebase-alpine-base-3-20-31 vCPU, 512 MB
H2Alpine Linuxclbalpinebase-alpine-base-3-20-31 vCPU, 512 MB
R1Cisco IOSvvios-adventerprisek9-m.spa.159-3.m91 vCPU, 512 MB
R2Cisco IOSvvios-adventerprisek9-m.spa.159-3.m91 vCPU, 512 MB

How to open this lab

  1. Sign in to your workspace at lab.cloudlabbox.com.

  2. In File Manager, open Shared, then the folder Linux for network engineers guided labs.

  3. Open 09 - Bash for network tasks - loop over hosts and parse output and start its nodes, then open Lab Tasks for the scenario and the steps.

The lab is read-only. You can start the nodes and configure the devices, but changes to the topology can’t be saved. To change it, rebuild it in your own folder.

More Linux for network engineers labs

All Linux for network engineers labs

Related labs in other courses

CloudLabBox is independent of Cisco, CompTIA, the Linux Foundation and the Linux Professional Institute. The lab follows exam topics and isn’t vendor training material; vendor names identify the exams and the images in the workspace.