Batch Script error checking

Discussion in 'Software' started by Gu55, Jul 22, 2014.

  1. Gu55

    Gu55 Private E-2

    Hi guys,
    I need some help.

    I'm trying to write a script to append a date as the file extension to the existing hosts file and then copy a blank hosts file to the location.
    This script is then deployed via LANDesk.

    My script runs successfully but LANDesk reports it as failed.

    Here's my script

    +++++++++++++++++++++++++
    @echo off
    Echo ----------------------------------------------------------------
    Echo Rename existing host & copy blank host file over
    Echo ----------------------------------------------------------------
    Echo
    Echo Rename existing host & copy blank host file over
    :CMD1
    ren %SystemRoot%\system32\drivers\etc\hosts hosts-%date:~-4,4%%date:~-7,2%%date:~-10,2%
    IF %ERRORLEVEL% == 0 (
    echo Original hosts file renamed successfully
    GOTO CMD2
    ) else (
    set ERRORLEV=10%ERRORLEVEL%
    GOTO FAILURE
    )

    :CMD2
    Xcopy.exe /r /y "\\SERVERNAME\LANDesk\packages\Deploy\Host File Scripts\Rename&Copy new hosts file\hosts" "%SystemRoot%\system32\drivers\etc\"
    IF %ERRORLEVEL% == 0 (
    echo New Host file copied over successfully
    ) else (
    set ERRORLEV=10%ERRORLEVEL%
    GOTO FAILURE
    )

    :FAILURE
    echo Rename existing host & copy blank host file failed with: %ERRORLEV%
    EXIT /B %ERRORLEV%

    :END
    echo Rename existing host & copy blank host file successfully
    +++++++++++++++++++++++++


    Here's my log from LANDesk
    +++++++++++++++++++++++++
    Processing package : Rename host file & copy blank file over
    Tue, 22 Jul 2014 12:31:30 File (\\cgbcdfvfs01\LANDesk\packages\Deploy\Host File Scripts\Rename&Copy new hosts file\Rename&Copy new hosts file v1.bat) is not in cache
    Tue, 22 Jul 2014 12:31:30 ILdDownloading file to C:\Program Files\LANDesk\LDClient\sdmcache\ldlogon\FileLists\taskmanifest.CGBCDFVLAN01.843.194.ini, attempt 0
    Tue, 22 Jul 2014 12:31:30 Only go to source for download.

    Tue, 22 Jul 2014 12:31:30 About to call DownloadFiles (1 files) with these settings:
    Tue, 22 Jul 2014 12:31:30 m_allowedBandwidthWAN: 25
    Tue, 22 Jul 2014 12:31:30 m_allowedBandwidthLAN: 75
    Tue, 22 Jul 2014 12:31:30 m_maxDiscoveryThreads: 15
    Tue, 22 Jul 2014 12:31:30 m_discardPeriodSeconds: 604800
    Tue, 22 Jul 2014 12:31:30 m_preserveDirectoryStructure: 1
    Tue, 22 Jul 2014 12:31:30 m_bUseWanBWForPush: 0
    Tue, 22 Jul 2014 12:31:30 m_bSynchronize: 0
    Tue, 22 Jul 2014 12:31:30 m_downloadControl: SourceOnly
    Tue, 22 Jul 2014 12:31:30 m_preferredServerControl: NoPreferredServer
    Tue, 22 Jul 2014 12:31:34 ILdDownloadFile returned 0
    Tue, 22 Jul 2014 12:31:34 processing of package is complete, result 229392397 (0x0dac400d - code 16397)

    Tue, 22 Jul 2014 12:31:34 File (\\cgbcdfvfs01\LANDesk\packages\Deploy\Host File Scripts\Rename&Copy new hosts file\Rename&Copy new hosts file v1.bat) is not in cache
    Tue, 22 Jul 2014 12:31:35 GetPreferredServerList(called on \\cgbcdfvfs01\LANDesk\packages\Deploy\Host File Scripts\Rename&Copy new hosts file\Rename&Copy new hosts file v1.bat) returned:
    Tue, 22 Jul 2014 12:31:35 cgbcdfvfs01.retail-group.net
    Tue, 22 Jul 2014 12:31:35 cgbcdvplan01.retail-group.net
    Tue, 22 Jul 2014 12:31:57 Putting preferred servers in the following order by time:
    Tue, 22 Jul 2014 12:31:57 cgbcdfvfs01.retail-group.net (4935)
    Tue, 22 Jul 2014 12:31:57 cgbcdvplan01.retail-group.net (12931)
    Tue, 22 Jul 2014 12:32:03 Download of '\\cgbcdfvfs01\LANDesk\packages\Deploy\Host File Scripts\Rename&Copy new hosts file\Rename&Copy new hosts file v1.bat' was redirected to '\\cgbcdfvfs01.retail-group.net\LANDesk\packages\Deploy\Host File Scripts\Rename&Copy new hosts file\Rename&Copy new hosts file v1.bat'
    Tue, 22 Jul 2014 12:32:26 Batch file Client Thread
    Tue, 22 Jul 2014 12:32:26 PackagePath: [\\cgbcdfvfs01\LANDesk\packages\Deploy\Host File Scripts\Rename&Copy new hosts file\Rename&Copy new hosts file v1.bat]
    Tue, 22 Jul 2014 12:32:26 Download of '\\cgbcdfvfs01\LANDesk\packages\Deploy\Host File Scripts\Rename&Copy new hosts file\Rename&Copy new hosts file v1.bat' was redirected to '\\cgbcdfvfs01.retail-group.net\LANDesk\packages\Deploy\Host File Scripts\Rename&Copy new hosts file\Rename&Copy new hosts file v1.bat'
    Tue, 22 Jul 2014 12:32:37
    Tue, 22 Jul 2014 12:32:37 Bat file output :

    C:\Program Files\LANDesk\LDClient>call "\\cgbcdfvfs01.retail-group.net\LANDesk\packages\Deploy\Host File Scripts\Rename&Copy new hosts file\Rename&Copy new hosts file v1.bat"

    ----------------------------------------------------------------

    Rename existing host

    The system cannot find the file specified.

    ----------------------------------------------------------------



    Rename existing host

    The system cannot find the file specified.

    Original hosts file renamed successfully

    \\cgbcdfvfs01.retail-group.net\LANDesk\packages\Deploy\Host File Scripts\Rename&Copy new hosts file\hosts

    1 File(s) copied

    Rename existing host

    The system cannot find the file specified.


    Tue, 22 Jul 2014 12:32:37 Installation result 8DB50001
    Tue, 22 Jul 2014 12:32:37 PostInstallInventoryScan: Getting post package install inventory delay setting.
    Tue, 22 Jul 2014 12:32:37 PostInstallInventoryScan: Initial delay value is '5' minutes
    Tue, 22 Jul 2014 12:32:37 PostInstallInventoryScan: Initial random delay value will be up to '15' minutes
    Tue, 22 Jul 2014 12:32:37 PostInstallInventoryScan: Actual random delay value is now '12' minutes
    Tue, 22 Jul 2014 12:32:37 PostInstallInventoryScan: Setting up local scheduler to launch inventory scanner with a delay of '17' minutes...
    Tue, 22 Jul 2014 12:32:37 PostInstallInventoryScan: Successfully created inventory scanner task.
    Tue, 22 Jul 2014 12:32:37 The nostatus flag has NOT been set.
    Tue, 22 Jul 2014 12:32:37 PostInstallInventoryScan: Getting post package install inventory delay setting.
    Tue, 22 Jul 2014 12:32:37 PostInstallInventoryScan: Initial delay value is '5' minutes
    Tue, 22 Jul 2014 12:32:37 PostInstallInventoryScan: Initial random delay value will be up to '15' minutes
    Tue, 22 Jul 2014 12:32:37 PostInstallInventoryScan: Actual random delay value is now '12' minutes
    Tue, 22 Jul 2014 12:32:37 PostInstallInventoryScan: Setting up local scheduler to launch inventory scanner with a delay of '17' minutes...
    Tue, 22 Jul 2014 12:32:37 PostInstallInventoryScan: Successfully created inventory scanner task.
    Tue, 22 Jul 2014 12:32:37 Sending task status, cmd line -coreandip=CGBCDFVLAN01:10.224.102.3 -taskid=843 -retcode=-1917517823 -complete -pkgid=194
    Tue, 22 Jul 2014 12:32:39 processing of package is complete, result -1917517823 (0x8db50001 - code 1)

    Tue, 22 Jul 2014 12:46:09 File (\\cgbcdfvfs01\LANDesk\packages\Deploy\Host File Scripts\Rename&Copy new hosts file\Rename&Copy new hosts file v1.bat) is not in cache
    Tue, 22 Jul 2014 12:46:09 ILdDownloading file to C:\Program Files\LANDesk\LDClient\sdmcache\ldlogon\FileLists\taskmanifest.CGBCDFVLAN01.843.194.ini, attempt 0
    Tue, 22 Jul 2014 12:46:09 Only go to source for download.

    Tue, 22 Jul 2014 12:46:09 About to call DownloadFiles (1 files) with these settings:
    Tue, 22 Jul 2014 12:46:09 m_allowedBandwidthWAN: 25
    Tue, 22 Jul 2014 12:46:09 m_allowedBandwidthLAN: 75
    Tue, 22 Jul 2014 12:46:09 m_maxDiscoveryThreads: 15
    Tue, 22 Jul 2014 12:46:09 m_discardPeriodSeconds: 604800
    Tue, 22 Jul 2014 12:46:09 m_preserveDirectoryStructure: 1
    Tue, 22 Jul 2014 12:46:09 m_bUseWanBWForPush: 0
    Tue, 22 Jul 2014 12:46:09 m_bSynchronize: 0
    Tue, 22 Jul 2014 12:46:09 m_downloadControl: SourceOnly
    Tue, 22 Jul 2014 12:46:09 m_preferredServerControl: NoPreferredServer
    Tue, 22 Jul 2014 12:46:13 ILdDownloadFile returned 0
    Tue, 22 Jul 2014 12:46:13 processing of package is complete, result 229392397 (0x0dac400d - code 16397)

    Tue, 22 Jul 2014 12:46:13 File (\\cgbcdfvfs01\LANDesk\packages\Deploy\Host File Scripts\Rename&Copy new hosts file\Rename&Copy new hosts file v1.bat) is not in cache
    Tue, 22 Jul 2014 12:46:18 Download of '\\cgbcdfvfs01\LANDesk\packages\Deploy\Host File Scripts\Rename&Copy new hosts file\Rename&Copy new hosts file v1.bat' was redirected to '\\cgbcdfvfs01.retail-group.net\LANDesk\packages\Deploy\Host File Scripts\Rename&Copy new hosts file\Rename&Copy new hosts file v1.bat'
    Tue, 22 Jul 2014 12:46:29 Batch file Client Thread
    Tue, 22 Jul 2014 12:46:29 PackagePath: [\\cgbcdfvfs01\LANDesk\packages\Deploy\Host File Scripts\Rename&Copy new hosts file\Rename&Copy new hosts file v1.bat]
    Tue, 22 Jul 2014 12:46:29 Download of '\\cgbcdfvfs01\LANDesk\packages\Deploy\Host File Scripts\Rename&Copy new hosts file\Rename&Copy new hosts file v1.bat' was redirected to '\\cgbcdfvfs01.retail-group.net\LANDesk\packages\Deploy\Host File Scripts\Rename&Copy new hosts file\Rename&Copy new hosts file v1.bat'
    Tue, 22 Jul 2014 12:46:34
    Tue, 22 Jul 2014 12:46:34 Bat file output :

    C:\Program Files\LANDesk\LDClient>call "\\cgbcdfvfs01.retail-group.net\LANDesk\packages\Deploy\Host File Scripts\Rename&Copy new hosts file\Rename&Copy new hosts file v1.bat"

    ----------------------------------------------------------------

    Rename existing host

    The system cannot find the file specified.

    ----------------------------------------------------------------



    Rename existing host

    The system cannot find the file specified.

    Original hosts file renamed successfully

    \\cgbcdfvfs01.retail-group.net\LANDesk\packages\Deploy\Host File Scripts\Rename&Copy new hosts file\hosts

    1 File(s) copied

    Rename existing host

    The system cannot find the file specified.


    Tue, 22 Jul 2014 12:46:34 Installation result 8DB50001
    Tue, 22 Jul 2014 12:46:34 PostInstallInventoryScan: Getting post package install inventory delay setting.
    Tue, 22 Jul 2014 12:46:34 PostInstallInventoryScan: Initial delay value is '5' minutes
    Tue, 22 Jul 2014 12:46:34 PostInstallInventoryScan: Initial random delay value will be up to '15' minutes
    Tue, 22 Jul 2014 12:46:34 PostInstallInventoryScan: Actual random delay value is now '0' minutes
    Tue, 22 Jul 2014 12:46:34 PostInstallInventoryScan: Setting up local scheduler to launch inventory scanner with a delay of '5' minutes...
    Tue, 22 Jul 2014 12:46:34 PostInstallInventoryScan: Successfully created inventory scanner task.
    Tue, 22 Jul 2014 12:46:34 The nostatus flag has NOT been set.
    Tue, 22 Jul 2014 12:46:34 PostInstallInventoryScan: Getting post package install inventory delay setting.
    Tue, 22 Jul 2014 12:46:34 PostInstallInventoryScan: Initial delay value is '5' minutes
    Tue, 22 Jul 2014 12:46:34 PostInstallInventoryScan: Initial random delay value will be up to '15' minutes
    Tue, 22 Jul 2014 12:46:34 PostInstallInventoryScan: Actual random delay value is now '0' minutes
    Tue, 22 Jul 2014 12:46:34 PostInstallInventoryScan: Setting up local scheduler to launch inventory scanner with a delay of '5' minutes...
    Tue, 22 Jul 2014 12:46:34 PostInstallInventoryScan: Successfully created inventory scanner task.
    Tue, 22 Jul 2014 12:46:34 Sending task status, cmd line -coreandip=CGBCDFVLAN01:10.224.102.3 -taskid=843 -retcode=-1917517823 -complete -pkgid=194
    Tue, 22 Jul 2014 12:46:36 processing of package is complete, result -1917517823 (0x8db50001 - code 1)
    ++++++++++++++++++++++++

    I'd be hugely gratefull if somebody could help.

    Thanks in advance
    Gu55
     
  2. foogoo

    foogoo Major "foogoo" Geek

    So you want to know why LANDesk is reporting a failure, even though the file is renamed and the blank is copied over?
    Or are you saying the script runs and doesn't do what it is supposed to?
     
  3. foogoo

    foogoo Major "foogoo" Geek

    the error "The system cannot find the file specified." are generated when the line:
    echo Rename existing host & copy blank host file over

    is executed in the batch, the errors are generated by the use of 'reserved' words. Take them out.
    @echo off
    Echo ----------------------------------------------------------------

    Echo ----------------------------------------------------------------
    Echo

    :CMD1
    ren %SystemRoot%\system32\drivers\etc\hosts hosts-%date:~-4,4%%date:~-7,2%%date:~-10,2%
    IF %ERRORLEVEL% == 0 (
    GOTO CMD2
    ) else (
    set ERRORLEV=10%ERRORLEVEL%
    GOTO FAILURE
    )

    :CMD2
    Xcopy.exe /r /y "\\SERVERNAME\LANDesk\packages\Deploy\Host File Scripts\Rename&Copy new hosts file\hosts" "%SystemRoot%\system32\drivers\etc\"
    IF %ERRORLEVEL% == 0 (
    echo New Host file copied over successfully
    ) else (
    set ERRORLEV=10%ERRORLEVEL%
    GOTO FAILURE
    )

    :FAILURE
    echo blank host file failed with: %ERRORLEV%
    EXIT /B %ERRORLEV%

    :END
    echo success
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds