Windows – Copy from linux to windows every minute

cpfile-sharingsambawindows

I currently quickly setup a way to copy files from my linux machine to a windows share that multiple people can access, but I'm looking for a better way.

In Windows 7, I made a folder accessible to Everyone.

In linux, I made the directory /mnt/windows_share and mounted the windows share using samba:

sudo mount -t cifs -o username=mouche,password=1234 //COMPUTERNAME/share_dir /mnt/windows_share

Then I ran this script using sudo in the directory I want to copy files from:

#!/usr/bin/perl -w
while (1)
{
    system("cp -u * /mnt/windows_share/");
    sleep 1;
}

One problem with this is that it updates Windows "Date Modified" properties every time it updates, even though I added the -u option to cp. Also, if the machine reboots, the mount command and the script have to be run again (with sudo, so you need to know the password).

Any suggestions on how to improve this process?

Best Answer

You should try rsync instead of cp: rsync -avz linux_path /mnt/windows_share/ and crontab instead of the perl loop: crontab -e and add the following line to it:

* * * * * rsync -avz linux_path /mnt/windows_share/

It's going to be executed every minute, and if that's an option in your case, it's more robust than the while loop.

Related Question