Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gavincarr/exec-capture

Utility to execute a command and capture its output to a given directory
https://github.com/gavincarr/exec-capture

Last synced: 28 days ago
JSON representation

Utility to execute a command and capture its output to a given directory

Awesome Lists containing this project

README

        

NAME
exec-capture - utility to execute a command and capture its output to a
given directory

SYNOPSIS
# usage: exec-capture [options] cmd [args]
exec-capture ifconfig
exec-capture -N ip_route ip route

DESCRIPTION
exec-capture is a simple wrapper utility to search the user's path for
an arbitrary command, execute it, and capture its output to a given
directory.

It is intended particularly for use from cron, to run a command
periodically and capture its output for aggregation or analysis.

OPTIONS
The following options are supported:

--help | -h | -?
Show usage information.

--verbose | -v
Run with more verbose output (may be repeated).

--noop | -n
Report command output to stdout instead of saving to the capture
directory. Implies --verbose.

--cmd | -C
Command to check for existence before execution. Defaults to the
first argument in @ARGV (i.e. the 'cmd' arg), so mostly only useful
if you're running a complex (e.g. piped) command line where you want
to test something other than the first cmd argument.

--name | -N
Name of the file to be used for capture output in the capture
directory. Defaults to the (basenamed) command name (from --cmd, if
given, else the first argument in ARGV), so should normally be
specified explicitly whenever you're going to run the same command
more than once with different arguments, or where you've got a more
complex (e.g. piped) command line where the first argument isn't the
most important e.g.

exec-capture -N ip_address ip address
exec-capture -N ip_route ip route

exec-capture -N blargle 'ls *.txt | blargle'

--dir | -d
Required. The directory to be used to capture output. May also be
specified via an EXEC_CAPTURE_DIR environment variable, so that it
can be set at the top of a cron job for multiple exec-capture
invocations. Default: none.

--missing-ok | -m
Flag to indicate that it is okay for the given command to be
missing. If the command is not found in the user's path we just
quietly exit instead of raising an error. This allows for cron jobs
to include optional exec-capture entries that gracefully exit on
hosts where the commands are not found.

--stderr | -e
Also capture stderr output, instead of just stdout.

--sort | -s
Sort output lines before capturing.

--sub
Apply (multiple) perl substitutions to command output before
capturing. This is useful, for instance, where you have
rapidly-changing data included in your output (e.g. temperatures,
traffic statistics, etc.) that you don't want to capture,
particularly if your tracking changes via a version control system.
e.g.

# remove RX and TX counter lines from ifconfig output
exec-capture --sub 's/^\s+(RX|TX).*\n//gm' ifconfig

May be repeated.

AUTHOR
Gavin Carr

COPYRIGHT AND LICENCE
Copyright (C) Gavin Carr 2011-2012.

This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself, either Perl version 5.8.0 or, at
your option, any later version of Perl 5.