5

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?

2 Answers 2

10

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.

2
  • 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, 2011 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, 2011 at 9:05
2

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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