Schedule copy of files from UNIX

Posted on 2014-08-14
Last Modified: 2014-08-23
Hi, i am, to say the least, a UNIX novice.  I have access to Putty and WinSCP.  I would like to find a method to schedule and automate the copy of a set of files (everything with the current date) from a UNIX server to a windows directory.

can anyone point me in the right direction?
Question by:greep
    LVL 35

    Expert Comment

    You have 3 problems. Scheduling. Easy in both unix and windows. Second up is transfer, WinSCP was working, but you can also turn it around and install something on the Windows side. Third is probably the most tricky. That's the download logic.

    You have to test a script either on the Unix side or Windows side. It doesn't really matter which side.
    If it's the unix side, you have to make sure you can reach the windows directory. On the Windows side, either share a drive, or install Filezilla Server. Test script, after that, use a cronjob to schedule it.
    If it's on the Windows side, test your winscp or ftp script, then schedule the job.

    Probably having a script at the unix side is easier, as otherwise you have no way to select to correct files (current date), unless the file name has this info.

    So, can you FTP to the Windows directory? That would make it a lot easier to follow up on this question.

    Author Comment

    Hi, thanks for your reply, you will have to, please, forgive my extreme ignorance of UNIX commands!.
    I can connect to the UNIX server using WINSCP, and manually drag/drop files to a mapped windows path.

    But i am not clear how, in a script I reach the Windows side.

    Could you perhaps give me an example script to copy files from a UNIX directory (with the current date) to a windows path?

    then, if i create the script on the UNIX server, how do I execute it from Windows?
    LVL 35

    Expert Comment

    Again, 3 problems: Scheduling/Transport/Logic
    You ask how to copy files from UNIX to windows. I'm missing the TRANSPORT part. How can the Unix machine reach the Windows PC? FTP ? SMB ?
    Then you ask to execute a script on UNIX from the Windows PC, but I thought you wanted to schedule it (which has to be done on the Unix side of course). Executing a script in Unix has to be done from the shell, as in an SSH session in PuttY. The scheduling of the cronjob too.
    LVL 27

    Expert Comment

    It would probably be easiest to schedule the logic from the Linux side to pick out the dates.  Create a folder and put links to files that you like to copy from the linux side, then copy them from the windows side with winscp using schtasks or the GUI scheduler.

    Create a folder to place the files that Winscp will copy from.
    mkdir /path/to/link/folder

    schedule a script to do the following;
    find /path/to/folder -mtime 0 -exec ln -s {} /path/to/link/folder/ \;
    The find command looks for files that have a mtime (modification time) of a 24 hour period, rounded up.  You can use other options for finer tuning, but this may be sufficient for your needs.

    To see more details
    man find

    You may want to schedule another task to delete all the links before you schedule Winscp to run on Windows.
    rm -r /path/to/link/folder/; mkdir /path/to/link/folder/
    or if you don't have hidden dot files
    rm -r /path/to/link/folder/*

    or you could just place it ahead of the find command in the script.
    LVL 40

    Expert Comment

    you need to do 3 things:

    1- have pscp (you can download to your windows):

    2- have a unix username and password

    3- schedule task to run on windows to run commands (could be a .bat file):

    drivename: (e.g. c:)
    cd \path]to\myfolder
    c:\path\to\pscp.exe -l username -pw password hostname:/path/to/myfiles/*.*

    Accepted Solution

    Thanks for your responses, I have found the solution.

    A unix script  along these lines:

    option batch abort
    option confirm off
    open sftp://userIid:password@unix.server
    cd /server/directory
    option transfer binary
    get filename C:\destination\

    saves as unixscript.txt

    and executed from a batch file using the command line:

    @echo off
    C:\Progra~1\Winscp\ /console /script=C:\unixscript.txt

    The batch file then added to the windows scheduler to fire at the desired time
    LVL 35

    Expert Comment

    A simple solution could have been provided by anyone. You seem to forget your original question was more intricate as indicated by "automate the copy of a set of files (everything with the current date)". Obviously, if you didn't mention that, a lot of people would have a script ready for you already. Your current script doesn't contain any of that logic.

    Author Closing Comment

    i managed to find the simpilest solution myself

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
    Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now