Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 10 down vote accepted

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.

share|improve this answer
1  
And it has the added advantage of being much more robust in its updating than cp -u so you'll have significantly less network overhead... Speaking of which, I'd argue that if that share is a nontrivial size you'd do better to update slightly less often –  Shadur Apr 1 '11 at 7:25
1  
You probably don't want -v with rsync run as a cron job unless you like lots of email. Even with no changes it will produce a few lines of output that will be mailed off. –  penguin359 Apr 1 '11 at 9:05

You can avoid having to remount the share (and also allow it to be mounted by unprivileged user accounts) by adding it to fstab (/etc/fstab).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.