Last active
May 4, 2021 19:57
-
-
Save frytaz/ccc886c1696d9c8b5b7e7810bf5336a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# cron script to monitor temporary staging dir and move .plot files into farm dir where is enough free space | |
# temp dirs separated by space | |
temp_dirs=(/mnt/staging) | |
# farm dirs separated by space | |
farm_dirs=(/mnt/farm-03 /mnt/farm-02 /mnt/farm-01) | |
for dir in "${temp_dirs[@]}"; do | |
plots=($(ls -d $dir/*.plot)) | |
if [ -n "$plots" ]; then | |
for plot_path in "${plots[@]}"; do | |
plot_file_name="$(basename $plot_path)" | |
plot_size=($(ls -l $plot_path | awk '{print $5}')) | |
echo "Plot file: $plot_path Plot size: $plot_size" | |
for farm_dir in "${farm_dirs[@]}"; do | |
space=`df -B1 | grep "$farm_dir" | awk '{print $4}'` | |
echo "Farm dir: $farm_dir Space Available: $space" | |
if (( space >= plot_size )); then | |
echo "Copy $plot_path to $farm_dir/$plot_file_name" | |
rsync -aP --remove-source-files $plot_path $farm_dir/$plot_file_name | |
echo "Done!" | |
break | |
else | |
echo "Not enough space on $farm_dir ($space) needed $plot_size" | |
fi | |
done | |
done | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment