Lenny
Lenny

Reputation: 917

Check periodically if folder has been created in a directory

I have a list of folders in a text file. I want to periodically check if all of these folders have been deployed into a directory using bash script.

I cannot use notify as not all of my servers are able to use this command.

Upvotes: 0

Views: 261

Answers (1)

Lin
Lin

Reputation: 690

How about do it in a while loop with sleep command. Something like this:

#!/usr/bin/env bash
while true; do
    # flag represents if the app is ready, 1=ready, 0=not ready
    is_ready=1
    while IFS= read -r line; do
        # ignore empty line
        [[ -n "$line" ]] || continue
        if [[ ! -d "$line" ]]; then
            is_ready=0
            break
        fi
    done < "path/to/folders_list.txt"

    if [[ $is_ready -eq 1 ]]; then
        echo "App is ready"
        break
    else
        # idle for 10 seconds
        sleep 10
    fi
done

Upvotes: 1

Related Questions