/build/static/layout/Breadcrumb_cap_w.png

Scripting Question


Running a Batch File

02/15/2017 3769 views
I am trying to create a K1000 Script to run a batch file. The batch file is just to xcopy 2 files from a network share to the %USERPROFILE%/Appdata/Roaming/SAP/Common folder. I have uploaded the .bat file and the two files that I want to copy in the dependencies. What else do I need to set in the Tasks in order for this script to run properly?

My bat looks like this, if correct..?

xcopy /s /Y "\\servername\folder1\SAP GUI 740\NWSAPADMIN\CustomerFiles" "%USERPROFILE%\APPDATA\Roaming\SAP\Common"
1 Comment   [ + ] Show comment

Comments

  • I have a FileSync that I use instead of a regular script. If you're merely copying files from one location to another, perhaps that's all you need.

    That said, my FileSync is conditional in that it first checks to ensure that the files I am copying are not already present.

    Also, when I am deploying files and a bat script, I package everything together in an archive, set all my actions and conditions in the bat file, and then my script merely calls the bat file.

    When Kace deploys my archive, it autoextracts it on my target. Then the bat file takes care of everything else.

All Answers

2
Keep a few things in mind:
1. by default the K1000 agent runs scripts as system service. So if you try to do this, it will fail.
2. you can run scripts as logged in user (which would be a good idea in that case) but need to verify that this user has the correct rights
3. if the files are static you should zip them and roll out via the KACE (add it as dependency to the script and unzip it), so you don't need to verify that other servers need to be online and the user has the correct rights etc
Answered 02/15/2017 by: Nico_K
Red Belt

  • Ok, so I have run the script under my admin credentials and uploaded the zip file as a dependency.

    My task is set to On Success: Unzip file

    Path is set to the destination folder of the .ZIP

    File: name of the .ZIP

    Target: %USERPROFILE%\Appdata\Roaming\SAP\Common
    • yes, and this will only copy the files for the admin user. If you want that the currently logged in user is pointed, use run as logged in user.
      Hopefully you used as path
      $(KACE_DEPENDENCY_DIR) (which is the variable for the local kbots, it is easier than checking this manually, all variables can be found by clicking on the question mark next to the tasks)
      • The script ran successfully but I still do not see the 2 files copied into the path I put in. I am running it under Run as Logged in User
        Output Log

        Running as: SYSTEM
        Directory DOES exist: C:\ProgramData\Dell\KACE\kbots_cache\packages\kbots\290
        Activity Log

        Checking if directory exists: C:\ProgramData\Dell\KACE\kbots_cache\packages\kbots\290
        Unzipping file: \\liv-it\E\SAP GUI 740 Packages\CustomerFiles.zip C:\Windows\system32\config\systemprofile\Appdata\Roaming\SAP\Common
        Started: 02/16/2017 15:35:20
        Finished: 02/16/2017 15:35:20
        Elapsed Time: 0 seconds
        Status: 1
        Output Log

        Running as SYSTEM
        Directory DOES exist: C:\ProgramData\Dell\KACE\kbots_cache\packages\kbots\290
        Activity Log

        Checking if directory exists: C:\ProgramData\Dell\KACE\kbots_cache\packages\kbots\290
        Unzipping file: \\liv-it\E\SAP GUI 740 Packages\CustomerFiles.zip C:\Windows\system32\config\systemprofile\Appdata\Roaming\SAP\Common