LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 10-07-2010, 03:19 AM   #1
lyschange
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, 03:40 AM   #2
ionrivera
Member
 
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/sync.sh)
Code:
 sudo -i vi sync.sh
my script goes like this (you can copy & paste):

Code:
#!/bin/sh
#

RSYNC=$(which rsync)
SSH=$(which ssh)
RUSER=root                # Supply your windows server user here
WINSERVER=192.168.0.10    # 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
PID=/var/run/sync.pid

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
        fi
}

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

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

exit $?
3. Dont forget to make your script executable and test it.
Code:
 chmod +x sync.sh
 ./sync.sh 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:
Code:
 crontab -e
and insert the ff:
Code:
# m h  dom mon dow   command
30 17 * * 1-5 /root/sync.sh start
30 7 * * 1-5 /root/sync.sh stop
Thats it! Hope that helps...

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


Reply


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 08:38 PM
HOW TO MAKE backup script LINUX CentOS5 copy data to another machine ytd Linux - Newbie 8 09-30-2009 02:54 PM
How to run a script to a remote linux machine from a windows machine squirrel001 Linux - Newbie 5 05-04-2009 07:06 PM
How do I copy files from a linux machine to a Windows machines? hello321_1999 Linux - Software 11 05-15-2006 02:58 PM
copy from windows machine to a linux machine s_deepblue Linux - Networking 3 03-12-2005 02:43 PM


All times are GMT -5. The time now is 02:38 AM.

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