#!/bin/bash

plugins=/usr/local/monitoring/nagios/libexec

if [[ "$#" -lt "3" ]]; then echo "Usage: check_output_convert <command> <args_or_two_double_quotes_if_none> <pipe_to_command> [pipe_to_command_args]"; exit 3; fi

command="$1"
args="$2"
pipecmd="$3"
pipecmd_args="$4"

out=`eval ${plugins}/$command $args 2>&1`
stat=$?

out=`echo "STATUS: $stat; $out" | $pipecmd $pipecmd_args`
stat=$?

echo $out
exit $stat
