Created
June 19, 2024 22:36
-
-
Save subtleGradient/8c02f3d9e4974abd02835676b82caf36 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
#!/bin/bash | |
function filter_until_hung() { | |
local match_string="$1" | |
shift | |
local cmd=("$@") | |
local tmpfifo=$(mktemp -u) | |
mkfifo "$tmpfifo" | |
"${cmd[@]}" >"$tmpfifo" 2>&1 & | |
local cmd_pid=$! | |
echo "Monitoring for '$match_string'. Command PID: $cmd_pid" | |
grep --line-buffered -m 1 "$match_string" <"$tmpfifo" && { | |
echo "Match found! Terminating command process (PID: $cmd_pid)..." | |
kill -SIGTERM "$cmd_pid" #>/dev/null 2>&1 | |
echo "Waiting for command process (PID: $cmd_pid) to complete..." | |
wait "$cmd_pid" | |
echo "Command process (PID: $cmd_pid) terminated." | |
rm "$tmpfifo" | |
echo "Exiting with status 0." | |
return 0 | |
} | |
echo "Match not found. Waiting for command process (PID: $cmd_pid) to complete..." | |
wait "$cmd_pid" | |
local cmd_status=$? | |
rm "$tmpfifo" | |
return "$cmd_status" | |
} | |
# Example usage | |
echo "Starting the yarn command..." | |
filter_until_hung "Seeded test users." yarn --frozen-lockfile --non-interactive --silent || exit 125 | |
echo "Yarn command completed or interrupted." | |
# Your remaining script | |
cd "$(dirname "$0")/.." | |
cd frontend | |
bun relay | |
STATUS=$? | |
echo "STATUS: $STATUS" | |
cd - | |
git co -f >/dev/null 2>&1 | |
exit $STATUS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment