Trigger Jobs to Watch Files on Linux

Follow

It is possible to use JAMS Triggers to monitor for a file on a remote Linux node and execute a Job based on a file event. Below is an example of a Trigger and Job that looks for a file and deletes it when it is present.

Creating the Job

To start, pick the Folder you'd like to create a new Job within. Name it something such as "DeleteFileLinux." Choose the Execution Method SSHAgent.

Proceed to enter an email address. The Username chosen here should be the one that connects to the Linux node. For the source, enter this:

#!/bin/bash

rm /home/kevin/rogue_file

Be sure to make the file path relevant to the Linux system. This will be the same file that is monitored in the next step.

After manipulating any other Job Properties, toggle the Checkbox to edit the Job Definition after adding. Next, open the Properties Tab and go to the Submit Options section and set the Username and Agent Node Name for the Linux node. Click the Save button to finish.

Creating the Trigger

Now, open the Triggers Tab within your Folder and create a new Trigger; name it something such as "Delete Rogue File".  

Click next to add a Trigger Event. Click the Add button and click File Event. For File Name, choose the same file that was chosen when the job to that deletes a file was created. Also choose the same Agent node and Username. Click the Save button.

Click Next to add an Action, and click the Add button and then Submit Job. Click the ".." to choose the DeleteFileLinux job. Click the Save button. Proceed and click Finish.

Now, whenever there is a file named /home/kevin/rogue_file on the remote note 192.168.1.32, JAMS will execute the job DeleteFileLinux on this remote node, which will delete rogue_file.

There are many possibilities with the combination of triggers and jobs; this example shows one way that they can be utilized.

Have more questions? Submit a request

Comments

  • Avatar
    Viyar, Jessica

    How often will it poll the agent for the file? Is it resource intensive and/or could it cause any performance issues by having multiple file triggers for every agent? Thank you in advance!

  • Avatar
    Gennaro Piccolo

    Hello Jessica,

    The linux file watch will poll every 5 seconds. It is not very resource intensive, although if there are many thousands of file watches you will still want to consider the footprint on the server. A file watch is akin to running a job on the agent, so the number of file watches should be considered along with the number of jobs running.