How_To_Linux_Solutions/day_2/scheduler.sh
2022-08-29 22:35:33 +02:00

20 lines
527 B
Bash
Executable file

#!/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