Page 1 of 1

How secure move file

Posted: 07 Oct 2010 00:54
by darioit
Hello everybody,

I have this 2 batch

the first batch run each time a new file come is a specific directory and make a queuing copy, this batch runs several times in a day randomly

Code: Select all

FOR %%x IN (%SND%\*) DO FOR /F "tokens=3 delims=." %%y IN ('DIR /B %%x') DO FOR /F "tokens=1 delims=;" %%z IN ('FINDSTR %%y %SCRIPTS%\c.txt') DO (
IF NOT EXIST %SND%\F\%%y TYPE NUL > %SND%\F\%%y
COPY /Y /B %SND%\F\%%y+%%x %SND%\F\%%y > nul
DEL /Q %%x
)


The second batch do only 1 operation, precisely move 1 time a day at scheduled time the result of the copy %SND%\F\cumulativefile.txt to another directory to consolidate the data

My question is how can run the second batch safety without overlap with the first copy batch

Regards
Dario

Re: How secure move file

Posted: 07 Oct 2010 01:48
by amel27
each script must check for present another, one way - find by CMD Window title, for this purpose add 2 lines in the beginning of CMD:

Code: Select all

title CMD_1
tasklist /nh /fo csv /fi "WINDOWTITLE eq CMD_2"|find /i "cmd.exe"&& exit /b 1

Code: Select all

title CMD_2
tasklist /nh /fo csv /fi "WINDOWTITLE eq CMD_1"|find /i "cmd.exe"&& exit /b 1

this 4 lines check self and another copy of CMD:

Code: Select all

title %RANDOM%
tasklist /nh /fo csv /fi "WINDOWTITLE eq CMD_1"|find /i "cmd.exe"&& exit /b 1
tasklist /nh /fo csv /fi "WINDOWTITLE eq CMD_2"|find /i "cmd.exe"&& exit /b 1

title CMD_1


P.S. for this method scripts shouldn't start in hidden mode

Re: How secure move file

Posted: 07 Oct 2010 02:12
by darioit
This is a good solution, but how can I repeat the move task automatically, because it is be submitted by another system only one time a day

Regards
Dario

Re: How secure move file

Posted: 08 Oct 2010 03:17
by amel27
your can't get win title remotely, but can get process name, therefore your may create personal CMD.EXE for each BAT/CMD by simple copy of original CMD.EXE, for example: CMD_1.EXE for CMD_1.BAT and CMD_2.EXE for CMD_2.BAT, and start in scheduler via command:

Code: Select all

CMD_X.EXE /C CMD_X.CMD

now, your may simple detect remotely running task... and for preventing of simultaneous start your may check twice through a different time interval:

Code: Select all

title %RANDOM%

tasklist /nh /fo csv /fi "WINDOWTITLE eq CMD_1"|find /i "cmd_1.exe"&& exit /b 1
tasklist /s Comp02 /nh /fo csv /fi "IMAGENAME eq cmd_2.exe"|find /i "cmd_2.exe"&& exit /b 1

ping -n 3 127.0.0.1 >nul
tasklist /s Comp02 /nh /fo csv /fi "IMAGENAME eq cmd_2.exe"|find /i "cmd_2.exe"&& exit /b 1

title CMD_1

Code: Select all

title %RANDOM%

tasklist /nh /fo csv /fi "WINDOWTITLE eq CMD_2"|find /i "cmd_2.exe"&& exit /b 1
tasklist /s Comp01 /nh /fo csv /fi "IMAGENAME eq cmd_1.exe"|find /i "cmd_1.exe"&& exit /b 1

ping -n 5 127.0.0.1 >nul
tasklist /s Comp01 /nh /fo csv /fi "IMAGENAME eq cmd_1.exe"|find /i "cmd_1.exe"&& exit /b 1

title CMD_2


Besides, this method can detect local hidden batch processes