executing bash loop while command is running

until is the opposite of while. It’s nothing to do with doing stuff while another command runs. For that you need to run your task in the background with &.

cp SOURCE DEST &
pid=$!

# If this script is killed, kill the `cp'.
trap "kill $pid 2> /dev/null" EXIT

# While copy is running...
while kill -0 $pid 2> /dev/null; do
    # Do stuff
    ...
    sleep 1
done

# Disable the trap on a normal exit.
trap - EXIT

kill -0 checks if a process is running. Note that it doesn’t actually signal the process and kill it, as the name might suggest. Not with signal 0, at least.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)