shell script to copy files frm a linux machine to a windows machine using SCP

I need a shell script to copy files frm a linux machine to a windows machine using SCP. The files keeps changing day-to-day. I have to copy the latest file to the windows machine frm the linux machine.

for example :In Linux, On July 20, the file name will be 20.txt and it should be copied to windows

On July 21, It will become 21.txt and it also should be copied.

I need a script to work this

You can try following command to get the name of latest file:

ls -lgt | head -2

$-rw-r--r--  1 admin     353 2011-07-19 18:14 message.txt

to get only file name:

ls -lgt | head -2 | awk '{print $7}'

$message.txt

I need a script for this. Let me clear the things in detail.

I have a linux machine, where the file gets changing everyday (new files will be updated everyday). I want to copy the most latest file to the windows server.

I can use scp for this.

scp -r [/path/filename] [login name@ip address] : .

Here the filename gets changing everyday and I want to copy the files to a specific folder in Windows. How to do this using a script which automatically does this on a daily basis???

Seek ur help to solve this..

The explanation you provided still seems unclear to me... but I assume that the file with unique name is generated by other application everyday, so you won't be requiring script to generate filename, but you only require a script to extract the name of latest file and scp it to windows machine....
The script I've provided you earlier, if you look carefully provides you latest file in that directory, however if you want some specific files only to be found in the result set, you can have 'grep' after 'ls -lgt', like

file_name=ls -lgt | grep regex | head -2 | awk '{print $7}'
$scp $file_name /windows/machine/path

To run this script daily you can put this script in cron schedule, I hope you are aware of it nicely!

:slight_smile: