Wiggins has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Back-ticks and bash
by haukex (Archbishop) on Oct 08, 2016 at 16:08 UTC | |
by Wiggins (Hermit) on Oct 09, 2016 at 13:32 UTC | |
|
Re: Back-ticks and bash
by shmem (Chancellor) on Oct 08, 2016 at 20:04 UTC | |
|
Re: Back-ticks and bash
by hippo (Archbishop) on Oct 08, 2016 at 16:10 UTC | |
|
Re: Back-ticks and bash
by kcott (Archbishop) on Oct 09, 2016 at 06:14 UTC | |
by Wiggins (Hermit) on Oct 09, 2016 at 13:29 UTC | |
by choroba (Cardinal) on Oct 09, 2016 at 20:10 UTC |