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.
More on Scheduling, automation and scripting
A database dump must run every night at 1:30 AM. How do you schedule it with cron so it is reliable?BeginnerConvert that nightly cron job to a systemd timer. Why would you?IntermediateA cron job runs every 5 minutes, but sometimes takes 8 minutes and two copies overlap, corrupting data. How do you prevent that?BeginnerYou have 300 servers running the same cron job at midnight, and they hammer a shared API. How do you fix it?IntermediateA job must run on the last day of every month. Cron has no "last day" field. What do you do?IntermediateYou inherited a server and need to know every scheduled job on it. Where do you look?Beginner