Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have in the past created cron job that copies files from one linux server to another. I am now looking for a similar soolution, but this time round I need to copy from linux to windows.
I would need to have the script copy the files from a dirctory on the ubuntu machine into a directory for the "current" month on the windows server.
Any help or suggestions please? I'm thinking that the server would have to in someway look at the file to determine the date and then to copy it into the directory for the current month.
1. Mount the Windows share on your Linux server and run your script in Linux
2. Run your script from Windows and SFTP to your Linux server
My past experience with Windows scripting is to avoid it whenever possible, so I tend to go for option 1 more than option 2. And if you already have the script written that does what you want in Linux, it shouldn't be very difficult to modify it for this purpose. You could also install an SFTP server on your Windows machine if you don't want to mount the folder directly in Linux.
I was looking at the option of installing the SFTP server on the Windows Box, I haven't done this before so just wanted to be sure what the best approach would be.
On the second part of my question, how would I get the script to check the age of the file on the Linux box and then to move it to the relevant folder on the windows box. These folders will be named Jan_2013, Feb_2013, Mar_2013, Apr_2013, etc. Without me having to update the script on the Linux box each month.
That depends a little on how you are determining age (created, accessed, modified), and whether you are copying all files or just the new ones. But in general you can use something like this, which looks at the modified date of the file and outputs the Mmm_YYYY based on modified date:
Code:
$ stat -c%Y your_file_here |xargs -I## date -d @## +%h_%Y
$ Jan_2013
So if you had a for loop that ran through your directory hierarchy to look for files, you could use a command similar to above to populate a variable storing which directory each file should be copied to.
I'm having a problem connecting to the server. I have installed freeSSHd and tested a direct connection through putty. All of these work using the setup username and password. I am connecting through port 21. When trying to sftp username@servername:21 I get access denied on my password.
This is connecting from an Ubuntu Server to a Windows Server.
Any advice?
Thanks.
Last edited by SalientAnimal; 01-31-2013 at 12:55 AM.
Reason: Added detail
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.