Interview Prep/Linux/Scheduling, automation and scripting

Your team wants scripts that work on both Ubuntu and RHEL hosts. How do you detect the distro reliably?

IntermediateScenarioScheduling, automation and scripting
Answer

Situation read → Use /etc/os-release, the standard.

What I'd do →

. /etc/os-release
case "$ID" in
  ubuntu|debian) pkg="apt-get install -y" ;;
  rhel|rocky|almalinux|centos|fedora) pkg="dnf install -y" ;;
  *) case "$ID_LIKE" in *rhel*|*fedora*) pkg="dnf install -y";; *debian*) pkg="apt-get install -y";; esac ;;
esac

Why → /etc/os-release exists on every systemd distro; ID_LIKE covers derivatives.

Interview tip → Say past a few branches you'd let Ansible facts (ansible_os_family) handle it.

All Linux questions Roadmap: Linux

More on Scheduling, automation and scripting