Ultimately I want to detect a new backup file being dropped into a directory and then move that new file to another location for other operations.
This needs to work when there is nobody logged into the server and the script I use to start the operation will be triggered by a crontab entry.
I tried using 'inotifywait' like this:
dir=/home/userid/drop/ target=/home/userid/current/ inotifywait -m "$dir" --format '%w%f' -e create | while read file; do mv "$file" "$target" done
This only works in you have a terminal window session open. If you try to start this scipt unattended using a crontab entry, the inotifywait command is ignored.
So then I tried using 'entr' and found the same problem. It only works if you have a terminal window open. When I created a script using entr and triggered it unattended with a crontab entry, it was ignored just like the inotifywait example.
So I know that this can be done using 'stat' and I have looked at many examples and tried to figure them out for my purpose, but I am just not understanding the syntax for it.
I know stat can detect the existence of a new file in a directory, but I do not know how to process that result in order to trigger the execution of the mv (move) command to move the new file to a different location.
And once I have a stat syntax that can do this, I will need it to run perpetually. Maybe it only checks every 15 seconds or something, but I will need it to always be prepared to move the file.
If anyone has experience doing this and can kindly help me with the syntax to link stat to executing another command, I would be greatly appreciative. I really believe that others would like to know how to do this as well, because I cannot imagine that everyone is ok with keeping a ssh putty window open 24/7 for the other 2 solutions.
Thanks in advance.