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
Problem with script
Moderator: DosItHelp
Re: Problem with script
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
-
- Posts: 104
- Joined: 28 Jul 2011 17:32
Re: Problem with script
Only good for Vista and above. XP doesn't have timeout.
Re: Problem with script
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.