03-27-2012 07:18 AM - edited 03-01-2019 08:52 AM
Hi,
I have a problem whereby I need to extract part of a filename picked up by a file event and use it to form a new variable for use in a subsequent job.
The way I'm thinking of doing this is taking the name of the file from <Filemon.Filename> feeding that into a script which will strip off the original extension and using what's left as the root of a new filename.
So lets say the file watcher picks up a file called 12345.req. I want to send that file to a remote site where it will be processed and they will create a response file called 12345.out which I then need to ftp back to my systems. The initial string is variable and cannot be predicted. There are also several hundred possible variants (eg aaa123.req, 123xxx456.req, XXX12345.req and so on) which are machine generated by a process designed 10 years ago.
The first step is easy.ie file event calls action which calls ftp put to send the original request file. In that step I set some group variable eg GROUP_FILENAME. I want to populate a value in another group variable called say REQUEST_FILENAME
What I need to do in unix terms is something like
FILE_PREFIX= `echo $GROUP_FILENAME | sed 's/\.req//' `
followed by (and this is where it gets vague)
tesmcmd varset -i <group ID> -n REQUEST_FILENAME -n "$FILE_PREFIX".out
Does this make sense or is there a better way to be going about this?
Cheers
Joe
03-29-2012 02:49 AM
Hi Joe,
I can see the logic, a lot depends on the construction of the job, group, event and action. The "varset -i" is going to look for a group's run number. The value you set for this GROUP variable with a varset will persist only for that run of the group. So assuming the file watch event triggers a job (eg my_var_set_job) to run varset, the triggered job needs to find the run number. As this triggered job will not itself be part of a group you would need to have started the group and have the group run an event (from its Job Events tab) which is triggered when the group becomes active. This would run an action which sets a public variable to the current group run number. Then, when your my_var_set_job is triggered it would do a
FILE_PREFIX= `echo $GROUP_FILENAME | sed 's/\.req//' ` ;
tesmcmd varset -i publicvarname -n REQUEST_FILENAME -n "$FILE_PREFIX".out
Cheers,
Alastair
03-29-2012 06:20 AM
Thanks for the tip. I've got it working.
The mains group has two variables defined; REQUEST_FILE and RESPONSE_FILE
File event picks up the request file.
This calls an action which calls the group with an override to set
The first job in the group calls a little two line script
RESPONSE_FILE_VAR=`echo $2 | sed -e 's/\.req/\.out.gz/'`
tesmcmd varset -i $1 -n RESPONSE_FILE -v $RESPONSE_FILE_VAR
The parameters supplied to this script are
I send the file
I then have a repeating FTP GET job which runs until it gets
All good.
Cheers
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide