LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 08-23-2010, 09:06 AM   #1
Jalindar
LQ Newbie
 
Registered: Feb 2010
Posts: 14

Rep: Reputation: 0
SMB share through script


Greetings!!

I want to copy my files on Linux machine to windows machine through script. This copy of files done automatic. Can anyone help me please?

Is it possible?
 
Old 08-23-2010, 09:36 AM   #2
suprstar
Member
 
Registered: Aug 2010
Location: Atlanta
Distribution: ubuntu, debian
Posts: 142
Blog Entries: 2

Rep: Reputation: 22
Sure, that's easy! There's 2 ways to do it.

One way, the way I'd do it - Make the folder where you want the files on the windows pc shared and writeable. Make a script on the linux box that mounts the share, copies the files to it, then unmounts it:

mount -t cifs //10.0.1.2/sharename -o username=myusername,password=mypassword /mnt/whatever/
cp /my/path/files.* /mnt/whatever
umount /mnt/whatever

Add this script to cron, and it will run whenever it's scheduled. Some distros have /etc/cron.daily, /etc/cron.weekly, /etc/cron.monthly etc. folders, and you can just put the script in whatever directory is appropriate (and dont forget to chmod it to be executable).

The other way would be to set up a samba share on the linux box, and make the windows pc map the drive, and copy whatever files it wants. IDK how to schedule a job on a windows PC, but it's basically the same concept, just making the windows PC do the work instead of the linux box.
 
1 members found this post helpful.
Old 08-24-2010, 12:56 AM   #3
toothandnail
Member
 
Registered: Apr 2007
Location: Oxfordshire, UK
Distribution: Arch, Sparky, Salix64
Posts: 85

Rep: Reputation: 7
As Suprstar suggests, having a shared, writeable folder on the Windows machine and mounting it through a script is the simplest way of doing it. There are a few things you need to consider if it is to be an automated operation....

First, it seems that mount sometimes takes a little while to settle, and attempting to write to the mounted share before it has settled will cause problems. Second, in an automated system, I would want a bit of error checking, and some way to tell if things have gone wrong.

This is adapted from a script I use to backup an SME server system to a Samba share:

Code:
#!/bin/bash
mount -t cifs - user=synbak%Synbak1 //192.168.1.10/share /mnt/backup
sleep 4 #allow the mount to stabalize before attempting to write to it
if [ -d /mnt/backup/box1 ]; then
     cp /home/notme/* /mnt/backup/box1
     sleep 20 #make sure any cached data has been written to the share
     umount /mnt/backup
else
     # Generate a log entry if the mount failed
     echo "`date +%m+%d-%R` Mount failed, backup aborted" >> /var/log/backup.log
fi
Using the -d test, I check fo the existance of a directory on the share (which checks that the mount command has worked), then go on with the copy. If the mount failed, I get a log entry that reminds me to check what went wrong. If the system is set up for it, an email message could be used instead of a log.

One other thing you need to consider is the type of files you are copying. If it is just data files, it probably doesn't matter. But, if you are backing up something like your home directory, you need to remember that copying files to a Windows share will not preserve the owner and permissions data that Linux uses. Under those circumstances, you would be better using something like tar (with optional compression) rather than copying. Tar will allow you to preseve the permissions and ownership data, which will prevent problems if you need to copy the files back.

In that instance, you could use something like this in place of the copy command:

Code:
tar czvpf /mnt/backup/box1/backup.tar.gz .
There are lots of other options, but that should give you some starting points.

Paul.
 
1 members found this post helpful.
Old 08-24-2010, 10:27 AM   #4
saikrishnaprasadh
LQ Newbie
 
Registered: May 2010
Posts: 4

Rep: Reputation: 0
Hi

i am using rhel5 in vm ware and in that i cant open the command terminal ...can anyone tell .how to make the command prompt open.
 
Old 08-24-2010, 10:33 AM   #5
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704

Rep: Reputation: 55
Quote:
Originally Posted by saikrishnaprasadh View Post
Hi

i am using rhel5 in vm ware and in that i cant open the command terminal ...can anyone tell .how to make the command prompt open.
Hi,

Welcome to LQ,

If you have any issue start a new thread. You have hijacked other's thread.

Press <ALT>+F2 then run the command gnome-terminal on the run prompt which opens terminal.

Last edited by vinaytp; 08-24-2010 at 10:34 AM.
 
Old 08-25-2010, 01:17 AM   #6
Jalindar
LQ Newbie
 
Registered: Feb 2010
Posts: 14

Original Poster
Rep: Reputation: 0
Hi saikrishnaprasadh,

Can you installed RHEL properly?

I think problem in installation. Do it again proper way.

Last edited by Jalindar; 08-25-2010 at 01:18 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
How can I mount a NFS share that have a SMB share mounted? perezyanez Linux - Networking 2 09-26-2008 10:03 AM
Placing a SMB share inside an NFS share grittyminder Linux - Networking 0 05-14-2008 04:49 AM
Smb share with AD eXor Linux - Server 1 02-18-2008 05:25 PM
script to upload backup file to smb share c_mitulescu Linux - Networking 1 03-15-2007 12:34 PM
smb share rajen_iiit Linux - Networking 4 08-09-2005 03:18 PM


All times are GMT -5. The time now is 06:33 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