confirmation on batch script

ivan rosa
ivan rosa used Ask the Experts™
on
Hello colleagues,

I have this one script to install firefox
psexec @clients.txt "c:\updates\firefox.exe" -ms 

Open in new window


however how would I translate and integrate the following idea?
result=0
if  error code==0 then %result%=success else %result%=failed >>%client%,%result%.csv

Open in new window


so I can get an output like this
Capture.PNG
of if anybody has a better idea would also work?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
NVITEnd-user support

Commented:
psexec @clients.txt "doit.bat"

Open in new window

doit.bat
set resultfile=\\server\share\firefoxrslt.csv
"c:\updates\firefox.exe" -ms 
if errorlevel 0 then (
  echo %computername%,success>>%resultfile%
) else (
  echo %computername%,failed>>%resultfile%
)

Open in new window

Author

Commented:
I just tried but it gave me an error,

PsExec could not start doit.bat on computer1

if I did doit.bat itself then will start the installation on the computer trying to launch it

and yet even though it gave me an error I didn't get any results...
NVITEnd-user support

Commented:
psexec @clients.txt -c -f "doit.bat"

Open in new window

Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

NVITEnd-user support

Commented:
if you do this in a cmd window:
"c:\updates\firefox.exe" -ms
echo %errorlevel%

Open in new window

...one of the the IF lines should be true.

Author

Commented:
we got passed the install now, although the result is still not showing up...
NVITEnd-user support

Commented:
Can it see firefox.exe? Move it to a share...
set resultfile=\\server\share\firefoxrslt.csv
"\\server\share\updates\firefox.exe" -ms 
if errorlevel 0 then (
  echo %computername%,success>>%resultfile%
) else (
  echo %computername%,failed>>%resultfile%
)

Open in new window

Bill PrewIT / Software Engineering Consultant
Top Expert 2016

Commented:
I didn't think firefox.exe returned negative errorlevel's, so won't this always be true?

if errorlevel 0 then (

~bp

Author

Commented:
firefox returns 0 for success and other than that is a failed unless if is directly from a psexec command will give something like 1xxx

so I just recreated something else again and this actually writes a file but the content is not quiet there yet

commander
for /f %%a in (clients.txt) do doit.cmd %%a

Open in new window


doit
"c:\updates\firefox.exe" -ms 
if %ERRORLEVEL% EQU 0 echo.%%a,success>>result.csv
if %ERRORLEVEL% NEQ 0 echo.%%a,failed>>result.csv

Open in new window


although the result it gives me is

and it doesn't collect the actual computer name from the variable...
%a      success
%a      success
Bill PrewIT / Software Engineering Consultant
Top Expert 2016

Commented:
Try this, the %%a gets passed to doit.bat as the first command line parm, so is referenced in doit.bat as %1.

"c:\updates\firefox.exe" -ms 
if %ERRORLEVEL% EQU 0 (
  echo.%1,success>>result.csv
) else (
  echo.%1,failed>>result.csv
)

Open in new window

~bp
Lee W, MVPTechnology and Business Process Advisor
Most Valuable Expert 2013

Commented:
Let me suggest an alternative solution that is far more expansive and easier... while not free, it's very inexpensive and no long term commitment (though I think HIGHLY worth the price).

Try Ninite - www.ninite.com - the Pro version can be scripted and also deploy to machines it finds in AD all at once.
NVITEnd-user support
Commented:
I use PDQ Deploy. The trial version will work across the domain. You just can't schedule it. The trial version can choose 3 packages. In your case, one would be Firefox.
I wish I could use a third party software.. aaah!

Author

Commented:
never found the right answer...

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial