Как я могу создать сценарий для контроля передачи файла включая исходное местоположение и целевое местоположение? (пример: Test.file от/home/Desktop до/home/Documents).
ответ ниже потребности inotify-tools
, который не мог бы быть в Вашей системе. Выполненный
sudo apt install inotify-tools
<час> , Как упомянуто в комментариях, Вы не можете "прервать" копию или переместить команды, если Вы не выполняете их в терминале и используете эти script
команда для записи то, что происходит.
Вы можете однако следить за тем, что происходит в каталоге, с [1 115] inotifywait
, которым был бы простой сценарий:
#!/bin/bash
DIR="/path/to/directory/to/watch"
inotifywait -m -r -e move -e create "$DIR" | while read f
do
# remove 'echo changed' after the test
echo changed
echo $f >> /path/to/logfile.txt
done
Просто устанавливает пути к каталогу в сценарии, сохраняют его как some_script.sh
и выполняют его. Более усовершенствованный, конечно, был бы к событиям метки времени, проанализировал бы вывод и т.д., но это - основная идея. Вместо того, чтобы "повторить" вывод, Вы могли использовать -o
опция, видеть человек inotifywait .
Для входа continuesly необходимо установить опцию -m
:
от [1 112]:
-m, --monitor
Instead of exiting after receiving a single event, execute indefinitely. The default behaviour is to exit after the first event occurs.
Для входа рекурсивно необходимо установить опцию -r
:
-r, --recursive
Watch all subdirectories of any directories passed as arguments. Watches will be set up recursively to an unlimited depth. Symbolic links are not traversed. Newly created subdirectories will also be watched.
, Кроме того, Вам нужно к [1 118], указывают событие (события) для инициирования:
EVENTS
The following events are valid for use with the -e option:
access A watched file or a file within a watched directory was read
from.
modify A watched file or a file within a watched directory was written
to.
attrib The metadata of a watched file or a file within a watched direc‐
tory was modified. This includes timestamps, file permissions,
extended attributes etc.
close_write
A watched file or a file within a watched directory was closed,
after being opened in writeable mode. This does not necessarily
imply the file was written to.
close_nowrite
A watched file or a file within a watched directory was closed,
after being opened in read-only mode.
close A watched file or a file within a watched directory was closed,
regardless of how it was opened. Note that this is actually
implemented simply by listening for both close_write and
close_nowrite, hence all close events received will be output as
one of these, not CLOSE.
open A watched file or a file within a watched directory was opened.
moved_to
A file or directory was moved into a watched directory. This
event occurs even if the file is simply moved from and to the
same directory.
moved_from
A file or directory was moved from a watched directory. This
event occurs even if the file is simply moved from and to the
same directory.
move A file or directory was moved from or to a watched directory.
Note that this is actually implemented simply by listening for
both moved_to and moved_from, hence all close events received
will be output as one or both of these, not MOVE.
move_self
A watched file or directory was moved. After this event, the
file or directory is no longer being watched.
create A file or directory was created within a watched directory.
delete A file or directory within a watched directory was deleted.
delete_self
A watched file or directory was deleted. After this event the
file or directory is no longer being watched. Note that this
event can occur even if it is not explicitly being listened for.
unmount
The filesystem on which a watched file or directory resides was
unmounted. After this event the file or directory is no longer
being watched. Note that this event can occur even if it is not
explicitly being listened to.
необходимо предварительно ожидать каждое из событий, чтобы быть инициированными, с [1 114]:
-e move -e create
, Конечно, можно установить любой триггер события из списка.
А короткий тест моего сценария часов дает нам вывод как:
/home/jacob/Bureaublad/test/Untitled Folder/ MOVED_FROM CV.pdf
/home/jacob/Bureaublad/test/Untitled Folder/ MOVED_TO CV.pdf
/home/jacob/Bureaublad/test/Untitled Folder/ MOVED_TO pscript_3.py
/home/jacob/Bureaublad/test/Untitled Folder/ MOVED_TO,ISDIR numpy
/home/jacob/Bureaublad/test/Untitled Folder/ CREATE Untitled Document 3
/home/jacob/Bureaublad/test/Untitled Folder/ CREATE,ISDIR Untitled Folder