Created
June 2, 2021 01:50
-
-
Save wallentx/60ea0f4524433627f640ff496c9614f2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| #set -x | |
| PIDPROCS=$(pgrep -fa 'chia plots create') | |
| if [[ -z ${PIDPROCS} ]]; then | |
| PIDARRAY="" | |
| PIDCT=0 | |
| else | |
| PIDARRAY=$(echo "$PIDPROCS" | awk '{print $1}') | |
| PIDCT=$(echo "$PIDARRAY" | wc -l) | |
| fi | |
| printPids() { | |
| for CHP in $PIDARRAY; do | |
| CH_PID=$(("$CHP" + 1)) | |
| paste <(echo "$CH_PID") <(journalctl _PID=$CH_PID --no-page --no-hostname -o cat | tac | grep -m1 -o "Starting phase .*" | cut -f1 -d'/') | |
| done | |
| } | |
| #printPids | |
| PHASE1=$(printPids | uniq -c | grep 'phase 1' | awk '{print $1}' | awk '{s+=$1} END {print s}') | |
| PHASE2=$(printPids | uniq -c | grep 'phase 2' | awk '{print $1}' | awk '{s+=$1} END {print s}') | |
| PHASE3=$(printPids | uniq -c | grep 'phase 3' | awk '{print $1}' | awk '{s+=$1} END {print s}') | |
| PHASE4=$(printPids | uniq -c | grep 'phase 4' | awk '{print $1}' | awk '{s+=$1} END {print s}') | |
| PHASE1PID=$(printPids | grep 'phase 1') | |
| PHASE2PID=$(printPids | grep 'phase 2') | |
| PHASE3PID=$(printPids | grep 'phase 3') | |
| PHASE4PID=$(printPids | grep 'phase 4') | |
| while getopts "acp" arg; do | |
| case ${arg} in | |
| a) if [[ -z $2 ]]; then | |
| echo "$PIDARRAY" | |
| elif [[ $2 -eq 1 ]]; then | |
| echo "$PHASE1PID" | |
| elif [[ $2 -eq 2 ]]; then | |
| echo "$PHASE2PID" | |
| elif [[ $2 -eq 3 ]]; then | |
| echo "$PHASE3PID" | |
| elif [[ $2 -eq 4 ]]; then | |
| echo "$PHASE4PID" | |
| fi | |
| ;; | |
| c) echo $PIDCT ;; | |
| #echo $(($(echo "$PIDARRAY" | wc -l)-1)) ;; | |
| p) P=$2 | |
| if [[ -z $P ]]; then | |
| echo "Phase1: $PHASE1" | |
| echo "Phase2: $PHASE2" | |
| echo "Phase3: $PHASE3" | |
| echo "Phase4: $PHASE4" | |
| else | |
| if [[ $P -eq 1 ]]; then | |
| echo "$PHASE1" | |
| elif [[ $P -eq 2 ]]; then | |
| echo "$PHASE2" | |
| elif [[ $P -eq 3 ]]; then | |
| echo "$PHASE3" | |
| elif [[ $P -eq 4 ]]; then | |
| echo "$PHASE4" | |
| fi | |
| fi ;; | |
| *) printPids ;; | |
| esac | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment