Copy file from unix box to another unix box

Hi,

I am new for perl scripting, I need a script to copy a log file /test/test_yyyymmdd.dat from one unix box to another unix box location /check/check1/ at daily 2:00AM, please let me know how to do that......

Regards,
Ann

you can do it by shell script also

check the man pages of cron and crontab.

and hete is simple automated ftp script.

Hi,
Thanks for your reply.
I will run the cronjob from the server1 ,the script should copy the file test/test_yyyymmdd.dat from server2 and it should get copied to server1 check/check1 location.
I think your script whatever u mentioned its doing in reverse way...from server1 i m able to copy to server 2 but i need copy from server 2 to server 1 using script running from server1.Please let me know to do the same.
Thanks,
Ann

oh!!
so u mean u don't want to "put" the file, but "get" it :wink:
There u go. :smiley:

Thanks it was working fine.
But the log file name is test_yyyymmdd.dat which is created daily in that /test folder, we need to get the last modified file i.e for example test_20080415.dat,test_20080418.dat are created in test folder it should copy the test_20080418.dat file to the server.

Regards,
Ann

take a look at the man page for 'date'. You will be able to construct the date field of the filename, and then with that value you will be able to use the script above.

-----------------
you can use also use remote copy
rcp -p server2:/test/test_yyymmdd.dat server1:/check/check1/

if you want to use the befits of date command, I recommend that you run the cron job at 23:59 to get the same date
or run abother cron job to get the date inside a file at any time during the day and run the copy cronjob at 2:00 AM and use the date from that file

Hello,

As far as I understand, now you want to know the latest file modified.

try:

ls -lrt

this would give u the files in the descending order of "Date Modified"
do a

head -1

to get the line u need and use awk to get the 9th column i.e the filename u require.

u can think of automating it, but try manually first.

Regards,
HKansal

Try this: schedule it in crontab

var=$(echo `date +" %Y%m%d "`)
rcp server2:/test/test_"$var".dat check/check1/

or

#!/usr/bin/ksh
var=$(echo `date +" %Y%m%d "`)
name=test_"$var".dat
cd /check/check1/
ftp -v -n server2 << EOF
user "username" "password"
cd /test/
get $name
quit
EOF

cheers,
Devaraj Takhellambam