A Bash script that collects hardware, OS, and network interface information from a Linux host and writes it to a structured output file.
Script: task4_1.sh
Output: task4_1.out
Target OS: Ubuntu 16.04 LTS (Xenial) — runs as root
The script produces task4_1.out with the following structure:
--- Hardware ---
CPU: Intel Xeon E5-2675
RAM: 8192 MB
Motherboard: ASUSTeK COMPUTER INC. P8Z77-M PRO
System Serial Number: S15747127820237
--- System ---
OS Distribution: Ubuntu 16.04.4 LTS
Kernel version: 4.4.0-116-generic
Installation date: Tue Mar 27 14:40:35 UTC 2018
Hostname: myserver.example.com
Uptime: 5 weeks, 4 days, 2 hours, 25 minutes
Processes running: 142
Users logged in: 2
--- Network ---
lo: 127.0.0.1/8
enp0s3: 192.168.1.37/24
virbr0: 192.168.122.1/24
virbr0-nic: -
| Field | Description | Example |
|---|---|---|
CPU |
Processor manufacturer and model (frequency, cores allowed) | Intel Xeon E5-2675 |
RAM |
Physical memory with unit (KB, MB, or GB — uppercase) |
8192 MB |
Motherboard |
Baseboard manufacturer + product name; Unknown if unavailable |
ASUSTeK COMPUTER INC. P8Z77-M PRO |
System Serial Number |
dmidecode -s system-serial-number; Unknown if unavailable |
S15747127820237 |
| Field | Description | Example |
|---|---|---|
OS Distribution |
Distro vendor, version, and optional code name (one line) | Ubuntu 16.04.4 LTS |
Kernel version |
Kernel version string — no spaces | 4.4.0-116-generic |
Installation date |
Human-readable date, parseable by date -d |
Tue Mar 27 14:40:35 UTC 2018 |
Hostname |
FQDN — characters: a-z A-Z 0-9 - ., no spaces |
myserver.example.com |
Uptime |
Time since last boot, to the minute | 5 weeks, 4 days, 2 hours, 25 minutes |
Processes running |
Total process count at script runtime (including the script itself) | 142 |
Users logged in |
Count of unclosed user sessions | 3 |
One line per interface (including loopback, VLANs, TAP, etc.):
<interface>: <IP>/<prefix>
- Multiple addresses on one interface are comma-separated:
192.168.1.37/24, 10.0.0.1/8 - Interface with no IPv4 address:
- - Allowed characters per line: digits,
./-,and spaces
- Format: Every line must follow
<Field>: <value>— exactly one space after the colon. - Order: Sections and fields must appear in the exact order shown above.
- No blank lines between fields within a section.
- The script must be idempotent — running it multiple times must always produce a valid
task4_1.out. - Any additional packages required must be installed automatically by the script (the VM starts from a clean Ubuntu 16.04 image with internet access).
The output file is validated automatically after each run. A field fails validation if:
- There is more than one space after the colon.
- The field name casing does not match exactly.
- A field contains characters outside the allowed set for that field.
- There are extra blank lines between fields.
- The output file is missing, has a different name, or is in a different directory than the script.
| Property | Value |
|---|---|
| Base image | ubuntu/xenial — cloud-img |
| Run as | root |
| Internet access | Yes |
| Additional packages | Allowed (must be auto-installed) |
Two additional scripts collect the same information on Windows machines. They are not part of the graded task — they are supplementary material.
| Script | Runtime | Output |
|---|---|---|
sysinfo_windows.ps1 |
PowerShell 3+ (built into Windows 8 / Server 2012 and later) | sysinfo_windows.out |
sysinfo_windows.py |
Python 3.9+ · auto-installs psutil via pip |
sysinfo_windows.out |
Run the PowerShell version:
# From the repo root (no elevated prompt required for most fields)
powershell -ExecutionPolicy Bypass -File .\sysinfo_windows.ps1Run the Python version:
python sysinfo_windows.pyBoth scripts write to sysinfo_windows.out in the same directory. The output format is identical to task4_1.out, with two Windows-specific adaptations:
| Field | Linux (task4_1.sh) |
Windows equivalents |
|---|---|---|
Kernel version |
Linux kernel (4.4.0-116-generic) |
Windows build (10.0.26200.0) |
Installation date |
Filesystem creation date via tune2fs |
Win32_OperatingSystem.InstallDate |
| Field | PowerShell source | Python source |
|---|---|---|
| CPU | Win32_Processor.Name |
Win32_Processor via PowerShell subprocess |
| RAM | Win32_ComputerSystem.TotalPhysicalMemory |
psutil.virtual_memory().total |
| Motherboard | Win32_BaseBoard.Manufacturer + .Product |
Win32_BaseBoard via PowerShell subprocess |
| Serial Number | Win32_BIOS.SerialNumber |
Win32_BIOS via PowerShell subprocess |
| OS Distribution | Win32_OperatingSystem.Caption |
Win32_OperatingSystem via PowerShell subprocess |
| Kernel version | [Environment]::OSVersion.Version |
platform.version() |
| Installation date | Win32_OperatingSystem.InstallDate |
Win32_OperatingSystem via PowerShell subprocess |
| Hostname | $env:COMPUTERNAME |
socket.gethostname() |
| Uptime | Win32_OperatingSystem.LastBootUpTime |
psutil.boot_time() |
| Processes | (Get-Process).Count |
len(psutil.pids()) |
| Users | Win32_LogonSession (type 2 + 10) |
len(psutil.users()) |
| Network | Get-NetAdapter + Get-NetIPAddress |
psutil.net_if_addrs() |
The repo includes a Vagrantfile and a validate.sh script so the solution can be verified locally against the same Ubuntu 16.04 environment used by the grader.
- VirtualBox 6.x or later
- Vagrant 2.x or later
# From the repo root — spins up Ubuntu 16.04, runs the script, prints the output
vagrant upThe provision step runs task4_1.sh as root and prints the resulting task4_1.out to the terminal. The file is also available at task4_1.out in the repo root (synced from /vagrant/task4_1.out inside the VM).
To re-run the script without rebuilding the VM:
vagrant provision
# or
vagrant ssh -c "sudo /vagrant/task4_1.sh && cat /vagrant/task4_1.out"To destroy the VM when done:
vagrant destroy -fvalidate.sh checks field order, exact names, spacing, and allowed characters — the same rules the grader applies.
# Run locally after copying task4_1.out out of the VM
bash validate.sh task4_1.outOr run it inside the VM directly:
vagrant ssh -c "sudo /vagrant/task4_1.sh && bash /vagrant/validate.sh /vagrant/task4_1.out"Expected output when everything passes:
OK: Line 1: --- Hardware ---...
OK: Line 2: CPU: ...
...
All checks passed.
multipass launch xenial --name task-vm
multipass transfer task4_1.sh task-vm:/home/ubuntu/task4_1.sh
multipass exec task-vm -- sudo bash /home/ubuntu/task4_1.sh
multipass exec task-vm -- cat /home/ubuntu/task4_1.out
multipass delete task-vm --purge