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 
  • No, the task is different: move files from the debian directory to the windows directory to process them with some software. The problem is that this software does not know how to log in to the samba directory on debian, so you have to transfer files. - RockerManchik
  • but where do the files come from? How often do they appear in this directory? what size do you have? - aleksandr barakin
  • files are documents of the work of the cyberft payment system terminal, as it is often difficult to say, there is no pattern, a payment document from a cyberft partner arrived, a file appeared, the sizes are small, up to kilobyte. - RockerManchik
  • The windows directory, with which the software processing files is working, is already mounted via nfs to debian, and documents from the terminal are transferred to it. Shl. If you are about to directly throw documents from the cyberft terminal into the mounted directory from Windows, then the developers do not go for it. - RockerManchik
  • one
    @NickVolynkin, the mv program has the option -v - aleksandr barakin

1 answer 1

as far as I understand, it is impossible to change the behavior of the program that creates files in the source directory, and tell it to save files not in /home/user/export/bin , but in /mnt/receipt/bin .

then you can replace the /home/user/export/bin with a symbolic link to the /mnt/receipt/bin :

 $ rmdir /home/user/export/bin && ln -s /mnt/receipt/bin /home/user/export/bin 

and you no longer need to move files: they will immediately be saved to where you want.

  • understandable, I'll try. - RockerManchik
  • Understood. The problem was not in the file transfer script, but in the software that processed the received documents on the win-resource. She, it turns out, deleted the files that processed. - RockerManchik