Interview Prep/Shell Scripting/Scenarios: text processing and scheduling decisions

Two servers that should be identical behave differently. Compare their installed packages.

BeginnerScenarioScenarios: text processing and scheduling decisions
Answer

Situation read → Generate normalized package lists from both and diff them.

What I'd do →

pkgs() { ssh -n "$1" "dpkg-query -W -f='\${Package} \${Version}\n'" | sort; }
diff <(pkgs web1) <(pkgs web2)
# names only, regardless of version
comm -3 <(pkgs web1 | cut -d' ' -f1) <(pkgs web2 | cut -d' ' -f1)
  1. On RHEL: rpm -qa --qf '%{NAME} %{VERSION}-%{RELEASE}\n' | sort.
  2. Extend to configs: diff <(ssh web1 cat /etc/sysctl.conf) <(ssh web2 cat /etc/sysctl.conf).

Why → Process substitution makes remote comparisons one-liners without temp files.

Interview tip → Mention that drift like this is the argument for immutable images or config management.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Scenarios: text processing and scheduling decisions