There was a problem of moving files that appear in one folder to another folder mounted on NFS. Debian system. Navayal simple script-1.sh , which does this and put on the execution of the crown with a period of once a minute. It was found that not all files are moved, some disappear, i.e. they are no longer in the src-directory, but they do not appear in the dst-directory.
I searched the network for this task with another script that would work on moving to the end of writing to a file. I found a certain script-2.sh , set it to be executed according to the IN_CLOSE_WRITE condition, using incrontab. Anyway, when moving files, some are lost.
Perhaps someone faced this problem already. Tell me how to eliminate this "loss" of files being moved.
script-1.sh:
cd /home/user/export/bin mv * /mnt/receipt/bin script-2.sh:
src_dir=$1 dst_dir=$2 subfolder="" sleep 2 # to set permissions if transferred by putty for filename in $src_dir/*; do echo " " $filename if [[ -f $filename ]]; then # regular file only { logger "$0 is going to move $filename -->" echo "$0 is going to move $filename -->" case "${filename,,*}" in # this syntax emits the value in lowercase: ${var,,*} (bash version 4) *.txt) subfolder="bin" ;; *) echo "Unknown file extension, don't know where to put $filename";; esac if [ -z "$subfolder" ]; then echo "subfolder is unknown $subfolder" else chmod 644 "$filename" #chown debian-transmission.samba-read "$filename" mv "$filename" "$dst_dir/$subfolder" fi logger "$0 finished <--" } else { echo "skipping $filename" } fi done; crontab -l
*/1 * * * * /home/user/scripts/export_bin.sh incrontab table
/home/user/export/bin IN_CLOSE_WRITE /home/user/scripts/export_bin.sh $@ /mnt/receipt/bin
-v- aleksandr barakin