Kaseya Community

Do to use a wild card in Get File

  • Hi all,

    I'm new to Kaseya and have the G1 Version.

    We have files on our Agents in the format YYYYMMDD.ZIP that get created daily. I've created a Get File script that will get a single file name but that's not want I want. I want to get the files daily as they are created.

    Specifying a Get File name like 2010*.ZIP produces errors.

    Is there a way of doing this and if so any help would be appreciated.

    TIA

    Greg

    Legacy Forum Name: Do to use a wild card in Get File,
    Legacy Posted By Username: ghines
  • You'll need to rename the newest file before using Get File. For example:

    1. Delete/archive example.zip (skip if fail)
    2. Execute Shell Command
    forfiles -d+0 -m*.zip -c"CMD /C rename @FILE example.zip"

    3. Get example.zip

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: SMason
  • SMason
    You'll need to rename the newest file before using Get File. For example:

    1. Delete/archive example.zip (skip if fail)
    2. Execute Shell Command
    forfiles -d+0 -m*.zip -c"CMD /C rename @FILE example.zip"

    3. Get example.zip


    And someone called me a command line guru... I've been trying to figure that one out for a while lol...

    Nicely done SMason!

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: thirteentwenty
  • Forfiles is case-sensitive with all of it's switches. Also, I don't think it likes spaces between the switches and parameters. In other words, it is very picky.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: SMason
  • Alternatively, run the following on your KServer:

    USE [ksubscribers]
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE VIEW [dbo].[v_Intech_CurrentDate] AS SELECT 'placeholder' AS Machine_GroupID, convert(varchar, getdate(), 112) AS CurrentDate;


    And then change your get file script to reference #v_Intech_CurrentDate.CurrentDate#.ZIP

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Intech-Jason
  • Hi,

    Thanks for both of the suggestions. However I have a couple of comments on both of them.

    The suggestion using forfiles is a good one but as most of my Agents are running XP forfiles is not installed on those agents by default.

    The SQL View suggestion I really liked but it failed to work without declaring the variable first even though I thought SQL Views parameters were automatically declared. I would get the error:-

    FAILED to create THEN step 1, Get File. Error = Script variable is undefined. It must be defined by a GetVariable step earlier in this script or a parent script.


    So I declared the variable using GetVariable and it too failed with the following error:-

    FAILED in processing THEN step 1, Get Variable, with error SQL query failed to return data in GetVariable task, SELECT CurrentDate FROM Intouch_CurrentDate WHERE (Machine_GroupID='harbourside.gj')


    Seems like the Machine GroupID was being included in the SELECT statement. So I replaced 'placeholder' in the View with a valid Machine GroupID and it worked.

    Problem is it will only now work with one Machine GroupID.

    Thanks for your assistance.

    Greg

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: ghines
  • Yeah, my fault on that one, I did that in a rush and didn't mention the view information. I use "placeholder" in scripts when I'm using Get Variable -> SQL View Data to minimize the impact of the query.

    In this case you can reference it with Get Variable -> SQL View Data by using:
    v_Intech_CurrentDate/CurrentDate/placeholder

    I think you can also modify the view to be:
    SELECT machName+'.'+groupName Machine_GroupID, convert(varchar, getdate(), 112) AS CurrentDate from MachNameTab;


    To return the machine information that Kaseya is looking for. Though I'm not sure if you can reference custom views in scripts without pulling the info first.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Intech-Jason
  • [QUOTE=Intech-Jason;61324]Yeah, my fault on that one, I did that in a rush and didn't mention the view information. I use "placeholder" in scripts when I'm using Get Variable -> SQL View Data to minimize the impact of the query.

    In this case you can reference it with Get Variable -> SQL View Data by using:
    v_Intech_CurrentDate/CurrentDate/placeholder

    I think you can also modify the view to be:
    SELECT machName+'.'+groupName Machine_GroupID, convert(varchar, getdate(), 112) AS CurrentDate from MachNameTab;


    To return the machine information that Kaseya is looking for. Though I'm not sure if you can reference custom views in scripts without pulling the info first.[/QUOTE]

    Thank you. Both suggestions worked just fine. Can you tell me why the variables must be declared as the manual suggests they don't?

    Note: - Automatic SQL View Data Variables - SQL view parameters are available as automatically declared script variables. Automatic variables enable you to skip using the GetVariable command with the SQL View Data option. Use the format #SqlViewName.ColumnName# in a script to return the value of a dbo.SqlView.Column for the agent executing the script.


    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: ghines
  • That I don't know, but they may only publish their own views. I haven't really messed around with it much.

    Btw, if you're using get variable and v_Intech_CurrentDate/CurrentDate/placeholder then you don't need the view that has the machine name in it, it's just extra overhead. You can use the original.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Intech-Jason