4 Replies Latest reply on Jun 16, 2008 6:25 PM by ldadmin

    Issue Executing a Batch File on a Remote Machine

    Rookie

       

      I am having an issue when trying to execute a batch file on a remote machine. Basically I have around 300 servers that I have copied a batch file to that I need to run. The batch file uses xcopy to copy files to other PC's on that servers domain.

       

       

      I have created a file copy script that copies the batch file from my machine to the servers. That part works as expected and copies the batch file to my specified location...

       

       

      I then created another task which runs a batch file that tries to execute the batch file I have copied to the servers. This is where I have issues. It seems that the batch file does run but the LANDesk scheduled task returns as failed. Also it doesn't complete the xcopy as expected.

       

       

      I have put some error handling in the batch file I use to execute the remote one. I have used things like:

       

       

      if exist C:\CopyUp.bat echo BLAH BLAH BLAH !!!! THIS WORKED >> YUP.DAT

       

       

      or

       

       

      if not exist C:\CopyUp.bat echo BLAH BLAH BLAH !!!! THIS WORKED >> NOPE.DAT

       

       

      In some cases I have found that the YUP.DAT & NOPE.DAT file is created meaning the batch file ran but the xcopy does not work. When I run the batch file manually on one of the servers the xcopy works and the files are moved as expected.

       

       

      Long story short I am hoping someone can help me out as there may be another way to execute this batch file on a remote machine.

       

       

      Thank you.

       

       

      Regards,

       

       

      Mitch

       

       

       

       

       

        • 1. Re: Issue Executing a Batch File on a Remote Machine
          Apprentice

          Its probably not working like you expect because the batch file is running as LocalSystem when launched by LANDesk, and when manually run its as a logged on user.

           

          Look at this link for more info on .bat files: http://community.landesk.com/support/docs/DOC-2320

          • 2. Re: Issue Executing a Batch File on a Remote Machine
            ProServices

             

            Hi,

             

             

            Might be a permissions thing. The script runs a local system, which is not a member of the everyone group, but is a member of "Domain Computers" ?

             

             

            Regards

             

             

            Ian

             

             

            • 3. Re: Issue Executing a Batch File on a Remote Machine
              ahe Expert

              Hello Mitch,

               

              add some more logging in your copy batch, to check the errorlevel of XCOP'Y:

               

              set errorlog=%temp%\errorlogfile.txt
              
              xcopy /S /E /R /Y "your_folder\your_source_files" "your_destination" >nul
              if errorlevel=4 goto ERR4_XCOPY
              if errorlevel=3 goto ERR3_XCOPY
              if errorlevel=2 goto ERR2_XCOPY
              if errorlevel=1 goto ERR1_XCOPY
              if errorlevel=0 goto REG_FILES
              goto UN_COPY_ERROR
              
              
              REM *****************************  XCOPY-Errors  ************************************
              :ERR1_XCOPY
              .>> %errorlog% echo %computername%;  No files to copy are found! 
              goto END
              
              :ERR2_XCOPY
              .>> %errorlog% echo %computername%;  The user breaks xcopy with STRG+C !
              goto END
              
              :ERR3_XCOPY
              .>> %errorlog% echo %computername%;  Initialization error, not enough memory or unknown drive name or wrong syntax!  
              goto END
              
              :ERR4_XCOPY
              .>> %errorlog% echo %computername%;  During write a error occured!
              goto END
              
              
              :UN_COPY_ERROR 
              .>> %errorlog% echo %computername%; Unknown error! 
              goto END 
              
              
              REM *********************************************************************************
              

               

               

              (delete the dot in the lines with ".>>" . I don't find a way to do ">>" in code without a dot...)

               

              As the other guys mentioned, it could be that the local system account of some servers do not have the rights to copy files to your wished location.

               

               

              You can find a great document here: About Batch File Distribution Packages

               

               

               

               

              Regards

              Axel

               

              Message was edited by: ahe >> can't be shown in code with out previous sign like dot.

              • 4. Re: Issue Executing a Batch File on a Remote Machine
                Rookie

                 

                Hi Guys,

                 

                 

                Thanks for your assistance. Although I have not got this to work as yet I am definately on the right track.

                 

                 

                Cheers