| 1 | #! /bin/sh |
| 2 | |
| 3 | set -e |
| 4 | |
| 5 | echo 'status' \ |
| 6 | | nc 127.0.0.1 6600 \ |
| 7 | | awk ' |
| 8 | { |
| 9 | status[$1] = $2 |
| 10 | } |
| 11 | |
| 12 | /^time: +[0-9]+:[0-9]+$/ { |
| 13 | split($2, time, ":") |
| 14 | seconds_current = time[1] |
| 15 | seconds_total = time[2] |
| 16 | |
| 17 | hours = int(seconds_current / 60 / 60); |
| 18 | secs_beyond_hours = seconds_current - (hours * 60 * 60); |
| 19 | mins = int(secs_beyond_hours / 60); |
| 20 | secs = secs_beyond_hours - (mins * 60); |
| 21 | if (hours > 0) { |
| 22 | current_time = sprintf("%d:%.2d:%.2d", hours, mins, secs) |
| 23 | } else { |
| 24 | current_time = sprintf("%.2d:%.2d", mins, secs) |
| 25 | } |
| 26 | |
| 27 | if (seconds_total > 0) { |
| 28 | time_percentage = (seconds_current / seconds_total) * 100 |
| 29 | current_percentage = sprintf("%d%%", time_percentage) |
| 30 | } else { |
| 31 | current_percentage = "~" |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | END { |
| 36 | printf(\ |
| 37 | "%s %s %s\n", |
| 38 | status["state:"], current_time, current_percentage\ |
| 39 | ) |
| 40 | } |
| 41 | ' |