Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 10-07-2010, 02:19 AM   #1
LQ Newbie
Registered: May 2010
Posts: 8
Blog Entries: 2

Rep: Reputation: 0
Copy folders from windows machine to linux script

HI all, im looking for a script to run that will be run from my linux box to copy folders from a windows server at a certain time on a dailly basis.
Old 10-07-2010, 02:40 AM   #2
Registered: May 2010
Distribution: Debian, RHEL, AIX, Solaris, HP-UX
Posts: 61

Rep: Reputation: 4
Thumbs up Copy files and folders from windows machine to your linux box using rsync and ssh

When copying files remotely even on windows, I use rsync and ssh to accomplish the task...

## PREREQUISITE: Install open-ssh on your windows server ##

1. On your Windows server and Linux box, add ssh keys to automate login without prompting for a password (there are lots of tutorial out there... just google)

2. On your Linux box, make a script (/root/
 sudo -i vi
my script goes like this (you can copy & paste):


RSYNC=$(which rsync)
SSH=$(which ssh)
RUSER=root                # Supply your windows server user here
WINSERVER=    # Change it with your windows server IP or Hostname
SRC=/shares/PUBLIC/       # Your windows shared folder via openssh-windows
DEST=/shares/BACKUP/      # Your linux box destination folder

start() {
        if [ ! -e "$PID" ];then
                touch $PID
                echo "Synchronizing files"
                $RSYNC -avz -e "$SSH" --delete $RUSER@$WINSERVER:$SRC $DEST

## Note: If you want to have an identical copy of files on both your windows shared folder and linux backup (acts as a mirror), you would need a "--delete" flag in your rsync routine. ##  

                rm -f $PID

stop() {
        if [ -e "$PID" ];then
                killall rsync
                echo "Stopping filesynching"
                rm -f $PID
restart() {

case "$1" in
                echo $"Usage: $0 {start|stop|restart}"
                exit 1

exit $?
3. Dont forget to make your script executable and test it.
 chmod +x
 ./ start
4. If you want to run the script e.g. daily that starts copying/syncing every 5:30PM and stops copying/syncing every 7:30AM, su as root on your Linux Box and:
 crontab -e
and insert the ff:
# m h  dom mon dow   command
30 17 * * 1-5 /root/ start
30 7 * * 1-5 /root/ stop
Thats it! Hope that helps...

Last edited by ionrivera; 10-07-2010 at 03:31 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't see shared folders between two linux machines and one windows machine d10nte Linux - Networking 2 05-13-2010 07:38 PM
HOW TO MAKE backup script LINUX CentOS5 copy data to another machine ytd Linux - Newbie 8 09-30-2009 01:54 PM
How to run a script to a remote linux machine from a windows machine squirrel001 Linux - Newbie 5 05-04-2009 06:06 PM
How do I copy files from a linux machine to a Windows machines? hello321_1999 Linux - Software 11 05-15-2006 01:58 PM
copy from windows machine to a linux machine s_deepblue Linux - Networking 3 03-12-2005 01:43 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:35 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration