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
//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
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':
df | grep -q /mnt/sharename
if test $? -ne 0 ; then
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:
# Backup at 2:15 A.M. every day. Run 'man 5 crontab' for help on the time format
15 2 * * * /path/to/backup.sh