Kaseya Community

How do I write output to a file on the Kaseya server?

This question is answered

I'm trying to make a simple script that pulls a line from my devices and then appends it to a central file on the Kaseya server. This is what I've got so far:

executeShellCommandToVariable("cat /home/sitecon/sc/versc",  "System", false, "Linux", "Halt on Fail")

This outputs a single line (for example):    10.209.1.

I want to run this on a hundred devices and append each out put to a .txt file on my Kaseya server.

I know I have to reference the #global:cmdresults# variable, but I'm not sure what would actually send it to a file on the Kaseya server rather than trying to write to a file on the device the procedure is running.

Any help or suggestion would be appreciated. I'm not having luck with google. Must be typing my question the wrong way.

Verified Answer
  • Instead of getting the results to a variable in the Agent Procedure, you can redirect output to a text file and then use GetFile() to pull that file up.

    That said, I rarely find much use in that functionality. It just is inconvenient to check and do anything with the results. The only time I find that useful is when I want to log something that I'm not really going to check, but may want to check in the future.

    If I want to know the results now, I'll e-mail it.

    If I want to audit data and make it easily accessible on demand, I'll write that data to a Custom Field.

    If I want to trigger an action based on the results I'll parse it in the Agent Procedure and schedule other Agent Procedures based on the results...or more likely, just write it to the Agent Procedure Log and use a SQL Job or the SQLWrite() function to let SQL Server parse it and do whatever comes next.

All Replies
  • Instead of getting the results to a variable in the Agent Procedure, you can redirect output to a text file and then use GetFile() to pull that file up.

    That said, I rarely find much use in that functionality. It just is inconvenient to check and do anything with the results. The only time I find that useful is when I want to log something that I'm not really going to check, but may want to check in the future.

    If I want to know the results now, I'll e-mail it.

    If I want to audit data and make it easily accessible on demand, I'll write that data to a Custom Field.

    If I want to trigger an action based on the results I'll parse it in the Agent Procedure and schedule other Agent Procedures based on the results...or more likely, just write it to the Agent Procedure Log and use a SQL Job or the SQLWrite() function to let SQL Server parse it and do whatever comes next.

  • We do this all the time, and this is the basis for how we discover new event codes to consider monitoring. We run this monthly on 3000+ agents. With a bit more advanced scripting than BAT, you can manipulate or format the data that's collected.

    The basic concept is to run the command on an agent, write it to a file and upload it (getFile) using the same file name for every agent. I have a simple script that searches the UserProfile folder where all the getfile data files live - find every file, then run TYPE {Filename} >> MasterFile.txt.

    So - basically two procedures - one to run on every system to collect the data into a file - "hostname:value" (you need the hostname to identify / associate the data in the master file!). Then a second procedure that runs on the VSA to collect all of the results into a single file. You can get that file any number of ways, including getfile or email.

    Glenn

  • I am assuming you are potentially going to use this in a report or some sort.  There is a couple way to go about it.

    Using the GetFile() as suggested already will store it for each machine in a folder located in "C:\kaseya\UserProfiles\UniqueRandomIDforEachComputer\GetFiles\".  I suggest that you make the filename unique (I use the computername_reason.csv) so you can copy them out easily in a script.  If you can in your procedure include the computer name in the CSV, then you can merge all the CSV files into one and have useful data.

    Another option that is easier is just create a custom field and then dump the output into there instead.  This way it is always quickly available, and if needed in a report just export to CSV.

  • I agree with , from your example it looks like you are dumping a small output,  just create a Custom field (you can even create one called "MISC" if you like, if this is a one-time project.    Use the GetVariable command to grab the file output to a variable, then use the updateSystemInfo command to update the field with your findings.

    You can then export it as CSV and create your reports in Excel.

    Another option it to write the output to the Agent Procedure log, and put a tag at the end of the output like $LinuxVer$

    You can then create a report that only includes that tag.     The output may not be as clean as a pure CSV dump, but this method is better for larger outputs, or if you don't want to mess with a Custom field.