LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 03-15-2012, 01:20 AM   #1
xombboxer
Member
 
Registered: Apr 2011
Posts: 63

Rep: Reputation: 0
Communicating between 2 linux machines / windows-lunux machines


I have situation here.
1. I want to copy files from one linux machine to other programically. I can use scp but how do i pass the password? Is there any other alternative ?

2. i need to copy files from linux to windows. manually i can do that using winscp tool, but how to do using scripts?
 
Old 03-15-2012, 03:04 AM   #2
devilboy09
Member
 
Registered: Nov 2011
Location: Iran
Distribution: Debian, CentOS, LFS, CloudLinux
Posts: 377

Rep: Reputation: 10
what programming language are you using?
 
Old 03-15-2012, 03:57 AM   #3
Satyaveer Arya
Senior Member
 
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,420

Rep: Reputation: 305Reputation: 305Reputation: 305Reputation: 305
Quote:
i need to copy files from linux to windows. manually i can do that using winscp tool, but how to do using scripts?
You can try mounting the Windows drive as a mount point on the Linux machine, using smbfs; you would then be able to use normal Linux scripting and copying tools such as cron and scp/rsync to do the copying.

It could be done with 'smbclient', which acts much like an FTP client to a Windows share. Check out the manpage: man smbclient and look for ways to script it with the -c option, or man expect to drive it.

Here's how I'd probably do it though:

1. Pick which user you're going to be when you sync the files. Log in as this user and type 'id', and get the numeric ID. You will use this ID in step 4
2. Become 'root'
3. mkdir /mnt/sharename
4. Edit your /etc/fstab file and add an entry something like this. Replace the user ID of 500 with your user ID. Replace sharename with your windows share name. Replance WINDOWSHOSTNAME with your host name or IP address. If you don't know the shares, run smbclient -L WINDOWSHOSTNAME.

Quote:
//WINDOWSHOSTNAME/sharename /mnt/sharename cifs credentials=/root/smblogin,uid=500,noauto,user 0 0
5. Edit /root/smblogin and put the following two lines in it

Quote:
username=YOUR_WINDOWS_USERNAME
password=YOUR_WINDOWS_PASSWOD
6. Log in as the user from step 1.

7. Try mounting the share: mount /mnt/sharename
8. If that succeeds, then write a script to do it automatically. Let's call it 'backup.sh':

Quote:
#!/bin/sh
df | grep -q /mnt/sharename
if test $? -ne 0 ; then
mount /mnt/sharename
fi
cp -r /path/to/dir /mnt/sharename/destination/
9. Use cron to run the script.

a. Type crontab -e
b. Put the following in the file:
Quote:
PATH=/bin:/usr/bin
# Backup at 2:15 A.M. every day. Run 'man 5 crontab' for help on the time format
15 2 * * * /path/to/backup.sh
 
  


Reply



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
Linux guest on Vmware is not communicating to other guest machines Saravana Linux - Virtualization and Cloud 2 10-25-2009 11:14 PM
How do u connect from windows os to linux machines? deostroll Linux - General 6 08-22-2009 08:37 AM
How to browse Windows machines from Linux Fred Affe Linux - Networking 13 02-05-2004 01:39 PM
Windows machines seeing Linux amchjine beeman Linux - Newbie 4 09-29-2003 02:21 PM
communicating two machines lakshman Linux - Networking 1 02-27-2003 01:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:39 PM.

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
Open Source Consulting | Domain Registration