Batch for configuration/data upgrades

March 29, 2010 at 22:35:15
Specs: MS-DOS 6.22
Hi. I'm trying do do batch file for upgrades of couple of DOS machines.

What i want is:
if local file (C:\) is the same (date size content?) as file on network (P:\) then continue else replace local file with network file.
this will be repeated for couple of files (autoexec.bat, config.sys, system.ini, etc ...)

I'm kinda stuck and can't figure how to do the "are files identical" part.


See More: Batch for configuration/data upgrades

Report •


#1
March 29, 2010 at 23:05:29
along these lines, not tested:
@echo off & setlocal
fc c:\dahdah p:\dahdah > nul
if %errorlevel% gtr 0 (
copy /y p:\dahdah c:\dahdah
)
::----- end -----
but looking at it, why not just do a straight copy, after all,
unless files are great-big, who cares?

Report •

#2
March 30, 2010 at 01:03:39
nbrane,

OP is using DOS 6x. No setlocal; no gtr.


fc bla bla > nul
if errorlevel 1 copy bla


=====================================
Helping others achieve escape felicity

M2


Report •

#3
March 30, 2010 at 03:52:25
Yeah, the OP might as well just copy file straight out. After all, FC pulls it over the network, and if you decide to perform the copy, you're pulling the file a second time.

Report •

Related Solutions

#4
March 30, 2010 at 04:15:17
Yes, but a copy should only be made if a copy is needed. If FC works on DOS6.22, I'm with M2 on this one

Report •

#5
March 30, 2010 at 04:26:32
R2 is right, as usual.FC does a read AND compares the two.


=====================================
Helping others achieve escape felicity

M2


Report •

#6
March 30, 2010 at 05:57:09
Hi. Thanks for replies, i'll try M2 solution tomorrow.

Reason why I want to compare files is, because if there are differences (unauthorized modification of local files, or updated files on network) I want to perform restart with correct files.


Report •

#7
April 1, 2010 at 04:26:28
Hi again.
Well... I'm still stuck.
I did test batch with following content, but can't get errorlevel out of it.

test.bat:
FC CONFIG1.SYS CONFIGX.SYS
ECHO KO ERRORLEVEL=%ERRORLEVEL%
IF ERRORLEVEL 1 GOTO DOUPDATE
GOTO NOUPDATE

:DOUPDATE
ECHO UPDATE AND RESET
PAUSE
EXIT

:NOUPDATE
ECHO NOUPDATE
PAUSE

results into:
.....
0000039E: 68 0D
0000039F: 6C 0A
FC: CONFIG1.SYS longer than CONFIGX.SYS

KO ERRORLEVEL=
NOUPDATE
Press any key to continue . . .


Report •

#8
April 1, 2010 at 06:38:17
"ECHO KO ERRORLEVEL=%ERRORLEVEL%"

I don't know why that line fails to put out a number.

Maybe post the rest of the bat.


=====================================
Helping others achieve escape felicity

M2


Report •

#9
April 1, 2010 at 07:09:45
It's whole bat (only first row is missing "ECHO OFF" ).
I'm testing it in Vmware virtual machine, i'll try it on real machine tomorrow.

Report •

#10
April 1, 2010 at 07:11:20
FC CONFIG1.SYS CONFIGX.SYS
ECHO KO ERRORLEVEL=%ERRORLEVEL%
IF ERRORLEVEL 1 GOTO DOUPDATE

You are checking the errorlevel of ECHO, not the errorlevel of FC

Errorlevel-checking can only be done on the last command executed


Report •

#11
April 1, 2010 at 17:17:52
old dos won't echo a %errorlevel%, only respond to it.
quite retarded, in my book. even the friggin response is limited to "greater than", so you have to do a lot of sucky testing to make sure you got it right.
@tvc, good point too: always grab errorlevel immediately or it will be disrupted by the next command.

Report •

#12
April 1, 2010 at 22:02:57
so. I did the test on real HW and result is same as in VMware.

I made another test bat, but again - not working...

tets2.bat results into 0000
ECHO OFF

FC CONFIG1.SYS CONFIGX.SYS
IF ERRORLEVEL 5 GOTO 5555
IF ERRORLEVEL 4 GOTO 4444
IF ERRORLEVEL 3 GOTO 3333
IF ERRORLEVEL 2 GOTO 2222
IF ERRORLEVEL 1 GOTO 1111
IF ERRORLEVEL 0 GOTO 0000

:5555
echo 5555
goto blargh

:4444
echo 4444
goto blargh

:3333
echo 3333
goto blargh

:2222
echo 2222
goto blargh

:1111
echo 1111
goto blargh

:0000
echo 0000
goto blargh

:blargh
PAUSE

also this one is not working:
::EL.BAT v2.15 (283 bytes)
::Displays errorlevel set by last program run
::by: Vernon Frazee 12/94 - Last mod: 03/97
::http://www.vfrazee.com
@echo off

FC CONFIG1.SYS CONFIGX.SYS
set a=Errorlevel|set b=|set c=for %%_ in (0 1 2
%c%) do if %a% %%_00 set d=%%_
if not %a% 200 set b=6 7 8 9
%c% 3 4 5 %b%) do if %a% %d%%%_0 set d=%d%%%_
if not %a% 250 set b=6 7 8 9
%c% 3 4 5 %b%) do if %a% %d%%%_ set d=%d%%%_
set a=|set b=|set c=|set d=|echo %d%


Report •

#13
April 1, 2010 at 22:32:03
I didn't find edit button so here is next post ...
EDIT: omg I'm blind found it now .... I have been probably thinking about solution too much :)

I can get errorlevel 1 this way "fc configx.sys" (FC: Insufficient number of file specifications) so errorlevels do work.
maybe under DOS it should return 0 even if files are different?
but then I also need to do the check differently.

so finally this seems to be working
@echo off

FC CONFIG1.SYS CONFIGX.SYS > err.txt
FIND "no" err.txt
IF ERRORLEVEL 1 GOTO DOUPDATE
GOTO NOUPDATE

:DOUPDATE
ECHO UPDATE AND RESET
PAUSE

:NOUPDATE
ECHO NOUPDATE
PAUSE


Report •

#14
April 1, 2010 at 23:09:40
maybe try to boil it down to bare nails. do something really "dumb" to kick error, then see what hapns:
@echo off & setlocal
type fartblog.yek
if errorlevel 1 echo levelone
if errorlevel 2 echo leveltwo?
if errorlevel 0 echo you actually have a file called fartblob.yek?
::----
then, assuming you don't, you should see "levelone".
then run your fc and immediately discharge the errorlevel (and, make SURE the confits are, indeed, different!):
fc config.sys configx.sys
if errorlevel 1 goto lev1
if errorlevel 0 goto lev0
:lev1
echo different
goto :xit
:lev0
echo same
:xit
::------ ooops!! damn!! sorry
you are indeed correct, i made a trip to the dungeon to check the dinosaur, and fc did not report the errorlevel on a file mismatch. good idea using the find!

Report •

#15
April 2, 2010 at 07:55:04
Of course, when checking errorlevel, the first question you should ask yourself is, do you KNOW that this command/script returns an exitcode ? Then, WHAT exitcodes does it return for what cases ?


Report •

#16
April 2, 2010 at 08:19:36
I'm going to boot in DOS and check.


=====================================
Helping others achieve escape felicity

M2


Report •

#17
April 2, 2010 at 08:44:38
You're right; NG in DOS.

It's a bit disconcerting to realize how limited DOS is.

But refreshing to get a snappy interface, after using CMD prompt, which is like jogging in wet cement.


=====================================
Helping others achieve escape felicity

M2


Report •

Ask Question