user3259712
user3259712

Reputation: 87

copying files from server to local automatically using batch command

I want to copy the particular logfile generated for each day in one of my server which i have access to my local daily automatically.

I prepared the batch commands as follows but didn't work as expected.

echo off

SET logfiles=\\PWWAS0015\UMS_Logs\server1\ums\service-*.log
rem set var = C:\Users\L068699\Desktop\test\src
echo %logfiles%
copy %logfiles%  C:\Users\L068699\Desktop\test\

set yesterday = [DateTime]::Today.AddDays(-1).ToString("yyMMdd")
echo %yesterday%
pause

The problem is that I cana ble to extract all the logs but couldn't get the log which are like service-2015-04-17.log. How can I extract this kind of log which are one day behind i.e. if today is 2015-04-24 I should get the previous day log file service-2015-04-23.log

Upvotes: 0

Views: 77

Answers (2)

Padex
Padex

Reputation: 1

Try this, may help you..

@echo
set source1="\\xxx" 
set dest="\\yyy"
pushd %source1%
for /f "usebackq" %%i in (`"powershell (Get-Date).AddDays(-1).ToString('yyyy-MM-dd')"`) do set yesterday=%%~i
copy "yourfilename %yesterday%.log" "%dest%"
popd

Upvotes: 0

npocmaka
npocmaka

Reputation: 57252

try like this:

pushd \\PWWAS0015\UMS_Logs\server1\ums\
rem set var = C:\Users\L068699\Desktop\test\src
::echo service-*.log



for /f "usebackq" %%a in (`"powershell (Get-Date).AddDays(-1).ToString('yyyy-MM-dd')"`) do set yesterday=%%a
echo %yesterday%
copy service-%yesterday%.log C:\Users\L068699\Desktop\test\
pause

Eventually you'll need NET command to map the network drivre:

NET USE  \\PWWAS0015\UMS_Logs /PERSISTENT:YES

(put the net use before the pushd if it does not work)

Upvotes: 1

Related Questions