Skip to main content
added 335 characters in body
Source Link
Marinos An
  • 889
  • 9
  • 13

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 

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; }' 

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 
added 29 characters in body
Source Link
Marinos An
  • 889
  • 9
  • 13

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; }' 

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]

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; }' 

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; }' 
Removes or reduces need for horizontal scroll bar on the long lines
Source Link
Chris Davies
  • 128.5k
  • 16
  • 179
  • 325

Not that efficient but I it seems to work.

strings /sbin/init | grep -q "/lib/systemd" && echo SYSTEMD; SYSTEMD strings /sbin/init | grep -q "sysvinit" && echo SYSVINIT; 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]

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; }' 

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]

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; }' 

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]

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; }' 
Source Link
Marinos An
  • 889
  • 9
  • 13
Loading