我正在尝试使用 inotifywait 来观看文件夹(/shares/Photos),当它检测到添加到该文件夹中的 jpg 时,我需要将其大小调整到子目录($small_dir)中。在照片管理器下会有许多 jpg 子文件夹。
这棵树看起来像这样
shares
-Photos
-Folder 1
-Folder 2
.
.
.
Run Code Online (Sandbox Code Playgroud)
基本上,每当有人将图片复制到folder 1我需要创建一个新的子文件夹,然后调整图像大小并将较小的版本放入该文件夹中。
所以树会变成:
shares
-Photos
-Folder 1
-Resized
-Folder 2
.
.
.
Run Code Online (Sandbox Code Playgroud)
到目前为止我的代码:
inotifywait -mr --timefmt '%m/%d/%y %H:%M' --format '%T %w %f' -e close_write /shares/Photos --includei "\.jpg|\.jpeg" |
while read -r date time dir file; do
changed_abs=${dir}${file}
small_dir=${dir}${target}/
printf "\nFile $changed_abs was changed or created\n dir=$dir \n file=$file \n small_dir=$small_dir \n"
# Check if the $small_directory exists, if not create …Run Code Online (Sandbox Code Playgroud)