Add day_2
This commit is contained in:
parent
2ffb6ae516
commit
325336fc18
2 changed files with 38 additions and 0 deletions
20
day_2/scheduler.sh
Executable file
20
day_2/scheduler.sh
Executable file
|
@ -0,0 +1,20 @@
|
||||||
|
#!/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
|
18
day_2/submitter.sh
Executable file
18
day_2/submitter.sh
Executable file
|
@ -0,0 +1,18 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
JOBS_DIR=~/day_2/jobs
|
||||||
|
|
||||||
|
# Get file path as first argument
|
||||||
|
FILE_PATH="$1"
|
||||||
|
|
||||||
|
# Get only the file name from the path
|
||||||
|
FILE_NAME=$(basename "$FILE_PATH")
|
||||||
|
|
||||||
|
# Get the date in wished format
|
||||||
|
DATE=$(date -Iseconds)
|
||||||
|
|
||||||
|
# Combine name of new file
|
||||||
|
NEW_NAME="$DATE"_"$FILE_NAME"
|
||||||
|
|
||||||
|
# Copy job file with new name
|
||||||
|
cp "$FILE_PATH" "$JOBS_DIR"/"$NEW_NAME"
|
Loading…
Reference in a new issue