How_To_Linux_Solutions/day_2/scheduler.sh

21 lines
527 B
Bash
Raw Normal View History

2022-08-29 20:35:33 +00:00
#!/usr/bin/env bash
JOBS_DIR=~/day_2/jobs
LOGS_DIR=~/day_2/logs
# Make sure that needed directories exist
mkdir -p "$JOBS_DIR"
mkdir -p "$LOGS_DIR"
# Listen to CLOSE_WRITE event to run script after copying is done
inotifywait -m -e close_write --format "%f" run | while read FILE
do
echo "Running job $FILE"
# Adding execution permission
chmod u+x "$JOBS_DIR"/"$FILE"
# Running job script with output and error redirection
"$JOBS_DIR"/"$FILE" 1> "$LOGS_DIR"/"$FILE".out 2> "$LOGS_DIR"/"$FILE".err
done