Q:

Wrong filename identified by inotify when file sent via rsync

I have the following script which uses inotify to detect changes inside a folder.  As you can see, I save the whole path plus the name of the potential new file under the variable VAR.  VAR is gonna be something like the string I have in comment.  When I paste something from another folder everything is OK but when a file is transferred there via rsync, then VAR is something like this/is/the/path/.filename.log. JgHKzP Meaning that a full-stop is added in front of the filename and .XXXXXX is added at the back of it.  For example I got this
/home/user/CarMonitor/logs/gps/.gps-2015-11-3-18-7-41.log. QvPgm9

I mean I can do some string changes and make it right but why does this happen?  Thanks in advance. 
#! /bin/bash
inotifywait -r -m /home/user/CarMonitor/logs -e create |        #Wait till new files arrive (Flags: -m for 'monitor', -e for 'event')
while read path action file; do
    #echo "The file '$file' appeared in directory '$path' via '$action'"    
    VAR=$path$file  
    #VAR="asddas/sd/f/sda/gps/sdfsdfsdfsd.log"  
    echo $VAR                                               
    //Do stuff
done

A:

What you're seeing is a common programming technique.  It's typically used when a program is going to replace an existing file with new contents. 
Say you have a file named foo that you want to replace with a new version.  You could open foo for writing, which truncates the file, then write the new content to the file.  But suppose your program crashes or otherwise fails to finish.  You don't have a good copy of foo any more--the old version is gone, and the new version is empty or incomplete. 
Instead, your program follows these steps:

Open a file with a different name, say .foo.tmp. 
Write the new content to this new file. 
When finished, rename .foo.tmp to foo. 

Now, if your program fails to finish, then it'll leave behind a temporary file .foo.tmp.  But the original file is still present, so nothing was lost. 
Rsync uses this technique by default to update files.  Your script subscribes to create events, so you're seeing creation of the temporary file.  If you were to subscribe to move events, you'd probably see the file being renamed to have the correct name. 
Rsync has some options to control this behavior.  See the man page here and search for "--inplace" and "--partial". 