I have found a bash script that seems to reliably identify 'system5-init', 'upstart', and 'systemd' as foundations for process control. Running the script in back-ticks has interpretation problems. Using 'system' will only return the exit value, not the STDOUT (which is possibly usable, but rather opaque).
When I run the file left in /tmp/ from the command line, it echos the appropriate string.#create the bash script to determine whic Init System my $tmpScript = "/tmp/whichSysInit"; my $whichInit = <<"END"; #!/bin/bash if [[ `/sbin/init --version 2>/dev/null` =~ upstart ]]; then echo using upstart; elif [[ `systemctl` =~ -\.mount ]]; then echo using systemd; elif [[ -f /etc/init.d/cron && ! -h /etc/init.d/cron ]]; then echo using sysv-init; else echo cannot tell; fi END open OPT, "> $tmpScript"; print OPT $whichInit; close OPT; chmod 0555, $tmpScript; #run that script to get answer my $rslt= `$tmpScript`; #unlink $tmpScript; # cleanup print " Initialization is $rslt\n"; #react to the result #if ($rslt =~/using\s(?<si>\S+)/){ # my $sysInit= $+{si};
I searched for the program '[[', but none was found./tmp/whichSysInit: 2: /tmp/whichSysInit: [[: not found /tmp/whichSysInit: 1: /tmp/whichSysInit: systemctl: not found /tmp/whichSysInit: 4: /tmp/whichSysInit: [[: not found /tmp/whichSysInit: 6: /tmp/whichSysInit: [[: not found Can not determine System Init mechanism <>. Exiting
The shell in the environmant is '/bin/bash'
Maybe the '#!' on line 1 isn't run? And bash isn't what is interpreting the script?
Thoughts?
It is always better to have seen your target for yourself, rather than depend upon someone else's description.
In reply to Back-ticks and bash by Wiggins
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |