Problem with script

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mor.bas
Posts: 66
Joined: 25 Apr 2012 04:28

Problem with script

#1 Post by mor.bas » 18 Mar 2013 03:43

Hi,
I have a a batch file that transferring files.
The problem that there is a system that ex cute this script and if the system tried to call it all at once the script can't write to log(because this log is used by other process) and not transferring the file.
What can resolved the problem?
I think like a solution that can check if the log open by other process and wait until it's end.
How to accomplish it?
Thanks in advanced..

The script:

echo off


set path=%1
copy %2 d:\Temp
for /f "tokens=* delims= " %%a in (%2) do call :loadFile %path% %%a

exit 0

REM Routine for loading one file

:LoadFile

set full_path=%1%2

echo %date% %time%: transferring %full_path% ... >> D:\Configuration\SSEE\Logs\files.log
"D:\Program_Files\WinSCP\WinSCP.com" /script=D:\Configuration\SSEE\Scripts\E3\winscp_script.txt /log="D:\Configuration\SSEE\Logs\E3SFTP.log" /parameter %full_path% >> D:\Configuration\SSEE\Logs\files.log 2>&1

if %errorlevel% == 0 (set status="successfully uploaded") else (set status="failed to upload"
D:\Program_Files\SendMail\Blat.exe D:\Program_Files\SendMail\DefaultBody.txt -subject "SSEE-EMAINT sFTP error transfering file - %full_path%" -server mailserver.sort.com -port 25 -f AMNA--DCA-APP-427@sort.com
)

echo %date% %time%: %full_path% was %status%... >>D:\Configuration\SSEE\Logs\files_transfer.log

goto :EOF

mfm4aa
Posts: 70
Joined: 13 Feb 2013 14:02
Location: Europe

Re: Problem with script

#2 Post by mfm4aa » 18 Mar 2013 08:38

Hi, you can use somewhat like this:

Code: Select all

@echo off &setlocal
set "test=test.txt"
:loop
:: wait 2 seconds
ping -n 3 localhost>nul
:: check if the file is ready, loop if not
copy /b %test%+nul %test% >nul 2>&1||goto :loop
endlocal

mor.bas
Posts: 66
Joined: 25 Apr 2012 04:28

Re: Problem with script

#3 Post by mor.bas » 18 Mar 2013 09:49

Any other suggestions?

Ranguna173
Posts: 104
Joined: 28 Jul 2011 17:32

Re: Problem with script

#4 Post by Ranguna173 » 18 Mar 2013 10:34

Instead of "ping" use "timeout"

Code: Select all

timeout 2 > nul

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Problem with script

#5 Post by Squashman » 18 Mar 2013 12:41

Ranguna173 wrote:Instead of "ping" use "timeout"

Code: Select all

timeout 2 > nul

Only good for Vista and above. XP doesn't have timeout.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Problem with script

#6 Post by foxidrive » 18 Mar 2013 16:20

mor.bas wrote:Hi,
I have a a batch file that transferring files.
The problem that there is a system that ex cute this script and if the system tried to call it all at once the script can't write to log(because this log is used by other process) and not transferring the file.
What can resolved the problem?
I think like a solution that can check if the log open by other process and wait until it's end.
How to accomplish it?


That script should not have any trouble writing to the log file - unless you have a different script or a concurrent script writing to the same log file.
The solution is to use a different log file.

To see if a file is in use you can try copying the log file etc, but there is no guarantee that the other process isn't going to use the log file at any tick of the clock as soon as your code has successfully copied the file anyway.

Post Reply