Not that efficient but I it seems to work.
strings /sbin/init | grep -q "/lib/systemd" && echo SYSTEMD strings /sbin/init | grep -q "sysvinit" && echo SYSVINIT strings /sbin/init | grep -q "upstart" && echo UPSTART It will print more lines if more than one strings match, which could be translated to "Can't guess". Strings used in grep could be slightly modified but when tested in the following os I always got one line.
- RHEL 6.4 [UPSTART]
- RHEL ES 4 (Nahant Update 7) [SYSVINIT]
- Ubuntu 16.04.1 LTS [SYSTEMD]
- Ubuntu 14.04.2 LTS [UPSTART]
- Fedora release 23 (online shell) [SYSTEMD]
- Debian GNU/Linux 7 (online shell) [SYSTEMD]
- Centos 7.6 (VM) [SYSTEMD]
A more simplistic approach of the same solution (but it stops at first match)
strings /sbin/init | awk 'match($0, /(upstart|systemd|sysvinit)/) { print toupper(substr($0, RSTART, RLENGTH));exit; }' Update:
As KCGD points out many systems don't come with strings installed. So a more portable alternative could be:
cat /sbin/init | awk 'match($0, /(upstart|systemd|sysvinit)/) { print toupper(substr($0, RSTART, RLENGTH));exit; }' 2> /dev/null