I have a server that receives
/home/my_user/dropdirectory every hour.
I installed incron utility and use incrontab -e entry to run a script whenever a new file shows up in /drop
Here is the script:
#!/bin/sh # # First clear the 2 immediate use directories rm /home/my_user/local_ready/* wait sleep 1 rm /home/my_user/local_restore/* wait sleep1 # Copy the file from the /drop /local_ready cp /home/my_user/drop/*.tar.gz /home/my_user/local_ready/ wait sleep 5 # Now move the file to the /current folder mv /home/my_user/drop/*.tar.gz /home/my_user/current/ wait sleep 1 # Next we delete any stray files dropped that are not # of the target type so we can keep /drop clean. rm /home/my_user/drop/* wait sleep 1 # Un-Tar the files into the /local_restore directory tar -xzf /home/my_user/local_ready/*.tar.gz -C /home/my_user/local_restore/ wait sleep 1 # This should complete the movement of files
The problem I have been running into is the file that gets copied to the
/local_restore directory is truncated as if the next command in the script is causing an interruption to the
At first I put sleep commands in it to try to get it to work, then I added wait commands after each command in the script to try to get it to work thinking that would force everything to wait until the cp command had finished copying the file to the next location.
I cannot even tell if the
tar command is working at all because it depends on the success of the
cp command further up the chain to have the file in place. Based on a test I ran with only a command to un-tar one of the files, I suspect it will not complete either before the script exits either. At least that occurred in a different 3 line test I used to test my timing theory.
mv command works just fine and the whole file gets moved as it should.
Can anyone identify why the commands run in the script seem to be unable to complete their task?
I have been asked to show the contents of the incrontab entry so here it is:
/home/my_user/drop/ IN_CREATE /home/my_user/bin/cycle_backups
(cycle_backups is obviously the name of the script file)
This is a KVM type VPS cloud server running Ubuntu 16.04 LTS and it has 10gb of memory with over 100gb of disk space. When the file is dropped, this is the only thing the server has to do other than system idle!
I will admit that my server is a bit slow, so when trying to copy a 200mb file to another directory it takes a second or two to complete even when I do it right at the command line.
I am at a loss to explain the problem, which makes it even harder to identify a solution.
Fair Warning: I am not the best at any of this, but I didn't think this should be such an impossible thing to accomplish.