Jump to content
bradpcmac

Run a Batch File & Pass in Parameters from Automate Script

Recommended Posts

Big Picture End-to-End functionality: In Automate, I set an EDF for a computer, which amounts to setting its "subscription" level (Basic, Pro, etc...). Based on that computer's "subscription", the customer needs to get certain files synchronized to it.

My Current & Proposed Solution:

I have a batch file that uses WinSCP to synchronize certain directories on an endpoint according to what value(s) are passed into the batch file as parameters. I have tested my batch file, and it is working correctly when I run it manually from any computer.

I'd like to use Automate to handle the scheduled running and updating of this script for a particular group of endpoints. I already have the Group and AutoJoin Search setup and working within Automate. I also have created the EDFs that can hopefully be used to pass the correct parameters into my batch file ("Basic", "Pro", etc...).

My idea is that I would keep one central copy of my batch file somewhere on the Automate server (we use an on-premises server) and then have Automate copy that script to the endpoint if the script has been updated since the last time the endpoint checked in. That way, if I need to change functionality of the batch file, I just have one place to do it (the Automate server). That's where I'm stuck first. Is it possible to store a file on the Automate server, have the Automate Agent check to see if that file is newer than a local file, and then download & replace the local file on the endpoint if it needs to be updated?

Then, the next part of my Automate Script would need to run that batch file (now copied locally on the endpoint) and pass in parameters which are determined by the EDF values I set in Automate. Is it possible to run a batch file with parameters passed in?

On the endpoint I need to regularly execute something like:

sync.bat Basic
  • this will run my script and sync the "Basic" files
  • "Basic" is a dynamic value that we can change in Automate via an EDF if the customer changes subscriptions

I appreciate any help you can give, even if it's just a piece of this puzzle 🙂

Share this post


Link to post
Share on other sites

You need to read the documentation on Automate Scripting, and specifically the "Execute Script" function.

To answer some of your questions:

  • No, there isn't anything that specifically can check for a newer file, you would have to basically expect that you will re-download the file any time you want to "check it".
  • Yes, you absolutely can pass custom parameters to a batch file called from an Automate Script.

If you can run the Automate script anytime you need to run the batch script on the agent, then Execute Script will transfer a copy each time, execute it, and then remove it from the agent. If the batch script needs to run as a scheduled task (independently of the Automate Script), then you can use the "File Write" (or Download File: Forced) function in the script to put a good copy on the endpoint each time the Automate script is run.

Share this post


Link to post
Share on other sites

Any chance you could throw a link to the documentation that you mention, Darren? I looked for it in university and didn't find anything; kind of stuck atm with a similar problem and I'm not sure what I need to change to fix it. Connectwise support linked me to an advanced scripting doc, but it doesn't mention anything about passing info from EDFs to scripts... the test script I created (all it does is "start  %SystemRoot%\@VAR@.exe" with the VAR in the EDF that I created. In this case that EDF has "Notepad" in it, so it should open notepad on the target machine, in this case me) just stays stuck at "Running" and notepad never opens. Thanks in advance and if I figure it out I'll update here.
 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...