Skip to content
fruhPublic

About

Simple tree task runner written in go

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

gow

Simple tree task runner written in go.

Jobs are shell commands arranged in a tree. Jobs on the same level run in parallel, child jobs start only after their parent succeeded. Results are cached per input, so a re-run skips jobs that already succeeded.

Build

go build -o ~/go/bin/gow .
# custom version string
go build -ldflags="-X 'main.Version=CUSTOM_VERSION'" -o ~/go/bin/gow .

Usage

gow -i example.com -jobs recon            # single input, jobs from $GOW_JOBS_DIR/recon.gow
gow -if domains.txt -jobs ./my.gow -t 10  # input file, 10 parallel jobs
gow -jobs-help                            # jobs file syntax and GOW_* variables

Exit code is 1 if any job failed, 2 on invalid arguments.

A job whose command exits with 75 says "not applicable now" (a tool that is switched off, nothing to do): it is shown as skipped, is not a failure, leaves no success marker (so it runs again next time) and its child jobs do not start.

Flag Meaning
-i / -if single input / input file (one of them is required)
-jobs jobs file path, or name without .gow looked up in $GOW_JOBS_DIR (default ~/gow/jobs)
-w work directory (default $GOW_WORK_DIR, else ~/gow)
-t parallel jobs (default 5)
-config file of KEY=value lines exported to every job
-force re-run jobs even if cached
-max-items maximum number of items a fan-out job may expand to (default 4096)
-tail lines of live output of one running job under the status bar (default 15, 0 disables)
-no-status disable the status bar and the live output (the bar lists running jobs and is shown only when stderr is a terminal)
-clean, -clean-all remove results of the current input / all inputs
-proxy, -replay-proxy, -cmd-options, -of exposed to jobs as GOW_* variables

Live output

On a terminal gow shows a panel under the status bar with the last lines of the output of one running job:

[ 3 running | 12 queued | 40 done | 1 failed ] scan[10.0.0.5] (12s), ...
 ◀ 2/3 ▶ scan[10.0.0.5] (12s)   ←/→ Tab: switch job
 Starting Nmap 7.94 ( https://nmap.org )
 ...
  • ← / → (or Tab, h / l) switch between the running jobs; when the shown job finishes the next one is selected.
  • The panel uses at most half of the terminal rows and is left out on terminals with fewer than 10 rows. -tail N sets the number of lines, -tail 0 or -no-status turn it off.
  • It needs a terminal on both stdin and stderr. With a pipe or in CI nothing changes. Ctrl-C works as before and the terminal is restored on exit.
  • Escape sequences and \r progress updates in the output are cleaned up; the full, untouched output stays in log/<job-id>/output.

Jobs file

# comment
+job 1: echo "runs first"
+job 2: echo "runs in parallel with job 1"
    +job 3: echo "runs after job 2"      # 4 spaces per level, no tabs
  • ${VAR} / $VAR are expanded from the -config file and the environment; anything else ($1, $(cmd), ${x:-default}) is left to bash.
  • Invalid lines are skipped with a warning that includes the line number.

Fan-out jobs

A job can expand at run time into one sub-job per item, e.g. one per IP of a subnet. Every item is cached on its own, so after a crash or a failure a re-run executes only the items that did not succeed (or are new).

+live[HOST_IP=10.0.0.0/24]: nmap -sn "$HOST_IP" -oN "${GOW_OUT_DIR}/ping_$HOST_IP.txt"
+scan[HOST_IP=hosts.txt chunk=16 maxage=7d workers=2]: nmap -p 123 $HOST_IP
    +vuln: nmap --script vuln "$HOST_IP"     # runs once per instance
  • [VAR=source] goes between the name and the :. source is a variable (${GOW_IN}), a file with one item per line (relative to GOW_OUT_DIR, so a parent job can write it), a CIDR (network and broadcast address are left out), or a generator $(cmd) that prints one item per line. CIDR entries inside a list are expanded too; duplicates are dropped.
  • The item is passed as the environment variable $VAR. Always quote it ("$VAR"): items come from files and tool output.
  • chunk=N passes N space separated items to one job (default 1), handy for tools that batch well. Chunks are cached by their exact content.
  • workers=2 runs at most 2 instances of this fan-out at once, so with -t 4 the other 2 workers stay free for other jobs. Only the instances are limited, their child jobs use the global workers. Changing it does not invalidate results.
  • maxage=7d re-runs a successful result once it is older than that (h, m, s, d; default: never).
  • Log lines name the item for children too (vuln[10.0.0.5]), cached ones show as Job skipped, and every fan-out ends with a summary such as [#] scan: 254 instances: 250 cached, 3 ran, 1 failed. The final totals include the number of cached jobs.
  • Child jobs run once per instance and see the same $VAR. Fan-outs can nest.
  • Instances are not forced to re-run when the job that produced the list ran again; -force still re-runs everything.
  • -max-items (default 4096) limits the expansion; CIDRs wider than /8 are refused.
  • A bracket without = stays part of the job name (+job[1]: ...).
  • A failed instance only blocks its own children; its siblings carry on, and the fan-out job itself counts as successful once the list was resolved.
  • Items removed from the list leave their old results in out/ and log/; all jobs share GOW_OUT_DIR, so write per-item output files.

Join job

A job that runs once after all instances (and their child jobs) finished:

+scan[HOST_IP=10.0.0.0/24]: nmap -p 123 "$HOST_IP" -oN "$GOW_OUT_DIR/scan_$HOST_IP.txt"
    +vuln: nmap --script vuln "$HOST_IP"
+merge[after=scan on=done]: cat "$GOW_OUT_DIR"/scan_*.txt > "$GOW_OUT_DIR/all.txt"
    +report: ./report.sh                   # a normal child of the join
  • after=NAME names an earlier fan-out job at the same level (anything else is skipped with a warning).
  • on=all-success (default): every instance and its whole subtree succeeded. on=any-success: at least one did. on=done: always, even if all failed. A join whose condition is not met is skipped (and not counted as failed).
  • The join sees $GOW_FAN_TOTAL and $GOW_FAN_FAILED.
  • It re-runs when an instance was executed again or the item list changed, otherwise it is cached. A join cannot wait for another join.

Editor support

editors/sublime/ has a syntax definition for Sublime Text 4: jobs, comments, fan-out and join annotations, invalid indentation, and the command highlighted as bash.

Copy gow.sublime-syntax and Comments.tmPreferences to a folder under Packages (Preferences > Browse Packages..., e.g. Packages/gow/). Files named *.gow are picked up automatically, other files via View > Syntax > gow jobs. syntax_test_gow.gow holds the syntax tests (Tools > Build With > Syntax Tests); they refer to Packages/gow/gow.sublime-syntax, so keep the folder name gow.

Notes: the $(cmd) generator of a fan-out is highlighted as bash too. GOW_* variables get no special colour (they look like any bash variable). Lines in the file that do not start with + or # are plain text, as gow ignores them.

Layout of the work directory

<work>/<input>/in/env.txt      GOW_* variables (used by GOW_DOCKER_CMD / GOW_PODMAN_CMD)
<work>/<input>/out/            working directory of every job
<work>/<input>/log/<job-id>/   output, log.yaml and a success or error marker

The job id contains a hash of the job's parent chain, name and command, so editing a command invalidates its cache.

Test

go vet ./... && go test -race ./...

About

Simple tree task runner written in go

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages