0

When wildcards is used with file trigger in autosys to watch multiple files, is there any way or attribute to get the file name which triggered it.

user7169406
  • 1
  • 1
  • 1
  • Do you need the file name in a program/script that runs after the file trigger? Or as an AutoSys global variable? – badjr Nov 16 '16 at 19:59
  • I need file name in the script to add conditions based on file name and invoke java class – user7169406 Nov 16 '16 at 20:11
  • Do you have a the jil configuration of your file trigger job? And do you have a job that triggers on success of the file trigger job? Edit that into your question if you have it. – badjr Nov 16 '16 at 20:30
  • As of now I dont have but can I know the how you are trying to achieve it. Also there are no complications in the one I am using now because its only to watch multiple files with same pattern but I want to get the file name which triggered the command on success. – user7169406 Nov 16 '16 at 20:34

1 Answers1

1

You can define the file trigger job using a JIL script:

insert_job: file_trigger
job_type: FT
machine: machine_name
owner: user_name
watch_file: /path/to/file/*pattern*
watch_file_type: CREATE

Then define a CMD job to execute a command after success of the file_trigger job:

insert_job: cmd_job
job_type: CMD
command: /path/to/script/script.sh
machine: machine_name
owner: user_name
condition: success(file_trigger)

In script.sh, you can find the files that match the pattern you are looking for:

#!/bin/bash
files=(/path/to/file/*pattern*)
echo "The first matching file was ${files[0]}"

${files[0]} holds the file name of the first file that matches the pattern. The first file that matches the file trigger's wildcard is also the same file that matches the shell script's wildcard.

badjr
  • 2,166
  • 3
  • 20
  • 31
  • Wont this give always the same file that is first file in the path which matches the pattern. I want the file which has triggered command on create. – user7169406 Nov 17 '16 at 04:52
  • @user7169406 Not sure if AutoSys has any features that will give the file that triggered the job. So the files that match the pattern will remain in the directory after the job is triggered? Would looking at the file with the latest time stamp work? – badjr Nov 17 '16 at 05:16
  • If many files are added at the same time, it would fail right – user7169406 Nov 17 '16 at 05:25
  • @user7169406 If multiple files were added, the file trigger wouldn't fail, but the shell script I have listed currently probably wouldn't find the correct file that triggered it. – badjr Nov 17 '16 at 05:51
  • Yes the file trigger wont fail, but I will not be able to get the filename that triggered it. – user7169406 Nov 17 '16 at 06:47
  • @user7169406 According to https://communities.ca.com/ideas/235716667, this feature was wish-listed, so it doesn't look like AutoSys has a built-in feature to get the file name that triggered it. However, the OP said that if there is a wildcard specified for the file name, the first matching file is selected. So the file that triggered the job should be the same file that the shell script finds. – badjr Nov 17 '16 at 19:24