and thanks in advance for any advice.
гm having trouble finding an answer to my question elsewhere. гve been working on в рукописный шрифт that will watch в directory, and then move поля to various other directories based on certain criteria. HerВs what гve got so far:
cd `dirname $0`/watch
while true
do
inotifywait -e moved_to ../watch --format "%f" | while read FILE
do
if $(echo "$FILE" | grep -q ".jpg"); then
cp "./$FILE" "../images/"
elif $(echo "$FILE" | grep -q ".mp4"); then
cp "./$FILE" "../videos/"
elif $(echo "$FILE" | grep -q ".mp3"); then
cp "./$FILE" "../audio/"
else
cp "./$FILE" "../other/"
fi
done
done
This рукописный шрифт works эксперт it should if one file at в time is двиньте into./watch, but if многообразный поля пашите двиньте, only the first of them gets двиньте from./watch to the corresponding directory. HerВs another разрабатывает I have, but am unsure how this would handle problems such эксперт trying to sort/move незавершил поля:
while true
do
inotifywait -e moved_to `dirname $0`/watch && /bin/bash `dirname $0`/autotorrent.sh
done
which will launch the following рукописный шрифт when поля пахал added:
cd `dirname $0`/watch
for i in *; do
if $(echo "$FILE" | grep -q ".jpg"); then
cp "./$FILE" "../images/"
elif $(echo "$FILE" | grep -q ".mp4"); then
cp "./$FILE" "../videos/"
elif $(echo "$FILE" | grep -q ".mp3"); then
cp "./$FILE" "../audio/"
else
cp "./$FILE" "../other/"
fi
done
Многообразный гm just not sure how best to handle moving поля which в мае or в мае not take значительный украл to copy. гve got several ты разрабатываешь, but none of them really seem to be the robust solution гm looking for.
Thanks again to anyone who some advice for я
Так как Ваши файлы могли быть Большими, cp
занимает время. В это время Вы, вероятно, пропускаете уведомления. Попытайтесь бросить весь cp
команды в фон путем добавления a &
каждому. Это вернет Вас к inotifywait
более быстрый.
Кроме того, Вы могли устранить набор вызовов к grep
путем выполнения:
j=${i##*.}
case "$j" in
jpg) cp $i ../images/ & ;;
mp4) cp $i ../videos/ & ;;
mp3) cp $i ../audio/ & ;;
*) cp $i ../other/& ;;
esac
Хотя я не вижу, почему Вы хотите сохранить копию каждого файла обоими каталогами, почему бы не использовать mv
вместо cp
?
@zpawwn: На далее man inotifywait
при чтении я нашел --monitor
, таким образом Ваш сценарий должен быть:
cd `dirname $0`/watch
inotifywait -e moved_to ../watch --format "%f" --monitor | while read FILE
do
j="${FILE##*.}"
case "$j" in
jpg) mv "$FILE" ../images/ & ;;
mp4) mv "$FILE" ../videos/ & ;;
mp3) mv "$FILE" ../audio/ & ;;
*) mv "$FILE" ../other/& ;;
esac
done
Позволить inotifywait
справьтесь с организацией очередей события файла и выложите имена файлов, поскольку она замечает их. Старый путь имел inotifywait
нахождение ОДНОГО нового файла и выхода, позволяя Вашему cp
выполненный материал, затем перезапустите наблюдение. Другие файлы (который прибыл одновременно) больше не являются новыми (они были там когда 2-е inotifywait
запущенный).