1 # `fag` (Fork After Grep)
4 fag(1) User Commands fag(1)
7 fag - daemonize program after a string was found (ForkAfterGrep)
10 fag [OPTIONS] PATTERN PROGRAM [ARGUMENTS...]
13 fag searches the PROGRAM for the string PATTERN. This is useful if a
14 program takes a while to initialize and prints a message to stdout or
15 stderr when ready. When placed in a script, fag blocks execution until
16 the pattern was found, then daemonizes the child process, returns the
17 PID on stdout and exits.
20 Behaviour Changing Options
22 Set a timeout of SECONDS seconds.
25 If given, send a signal to PROGRAM. SIGNAL defaults to SIGTERM
26 (15). Right now, only decimal notation is implemented.
28 -e Search PATTERN on stderr instead of stdout.
30 Generic Program Information
31 -h Output a short usage message and exit.
33 -v Display version and copyright information and exit.
36 If PATTERN was found, 0 is returned. Otherwise, the exit status follows
37 the BSD guideline outlined in #include <sysexits.h> if the error
38 occured from within fag or in case the chid process exits prematurely,
39 its exit code is inherited. Notably, 69 is returned when the timeout is
44 Only a simple string search is performed on PATTERN in this version.
46 If a PROGRAM like cat opens stdout/stderr, but never writes to it, the
47 timeout isn't triggered.
49 SIGNAL needs to be given as an integer; mnemonic should be supported in
52 Sometimes, stdin behaves strange after the program terminates.
55 Please report bugs and patches to the issue tracker at
56 https://github.com/girst/forkaftergrep/.
59 Some might find the name of this program offensive. Feel free to create
60 a symlink or alias on your system.
63 Copyright 2017 Tobias Girstmair. This is free software; see
64 https://www.gnu.org/licenses/gpl-3.0.html for conditions.
67 Tobias Girstmair (http://isticktoit.net)
69 1.0 07 February 2017 fag(1)
74 I've written this program for the [`tzap`/`szap`](https://linuxtv.org/wiki/index.php/Zap) utilities. They take a few seconds until the TV card/stick is tuned, and won't fork off when they are ready (If you terminate them, the tuning will end). Instead of waiting a few seconds, and hoping for the best, this does the exactly right thing.