Skip to content

Instantly share code, notes, and snippets.

@jeffrade
Last active February 19, 2019 22:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffrade/9af16cd8f70097cc181ad2ab12988f4b to your computer and use it in GitHub Desktop.
Save jeffrade/9af16cd8f70097cc181ad2ab12988f4b to your computer and use it in GitHub Desktop.
Bash script that will pop a line item for a file and pass it to a command.
#!/bin/bash
echo "Starting..."
param=`sed -e 1$'{w/dev/stdout\n;d}' -i~ params.out`
while [[ -n $param ]]; do
echo "Starting process for $param..."
<some-command> $param &
curr_pid=`echo $!`
echo "Current pid is $curr_pid"
is_running="yes_it_is"
while [[ -n $is_running ]]; do
echo "Sleeping..."
sleep 5s
is_running=`ps -ww -fp "$curr_pid" | grep <some-useful-regex-for-command>`
#echo "debug: $is_running"
done
echo "Last process for $param completed!"
echo "Popping next param..."
param=`sed -e 1$'{w/dev/stdout\n;d}' -i~ params.out`
done
echo "Done!"
@jeffrade
Copy link
Author

TODO

  • Have <some-command> pass in as command line arg to this script.
  • Have <some-useful-regex-for-command> pass in as command line arg to this script.
  • DRY this script, i.e. move duplicated code to function(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment