natxo has asked for the wisdom of the Perl Monks concerning the following question:
Quite straight forward. I have killed -9 (yes, with signal 1 or 15 then they are not in a failed state, you need to really kill them) two services and then I run this and get this:use IPC::Cmd qw[can_run run run_forked]; my $cmd = "systemctl --failed --no-legend"; my ( $success, $error_message, $full_buf, $stdout_buf, $stderr_buf ) = run( command => $cmd, verbose => 0 ); if ($success) { my $nr_els = @$full_buf; if ( $nr_els == 0 ) { print "OK: all systemd units in their desired state\n"; } else { print "WARNING: "; print "$nr_els systemd units not running\n"; for (@$full_buf) { print "$_\n"; } } }
Why do I get '1' instead of 2? When looping throught the elements of @$full_buf I get two lines of text, so I should also get '2' in $nr_els but I get '1'.WARNING: 1 systemd units not running avahi-daemon.service loaded failed failed Avahi mDNS/DNS-SD Stack packagekit.service loaded failed failed PackageKit Daemon
I must be missing something very basic ..., but I cannot see it. Thanks for your input!
- Comment on number of elements in array ref wtf
- Select or Download Code
| Replies are listed 'Best First'. | |
|---|---|
|
Re: number of elements in array ref wtf
by haukex (Archbishop) on Jul 13, 2017 at 19:00 UTC | |
by natxo (Scribe) on Jul 13, 2017 at 19:20 UTC | |
by Anonymous Monk on Jul 14, 2017 at 01:41 UTC |