cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1327
Views
0
Helpful
2
Replies

Variable handling question

Joe Fletcher
Level 1
Level 1

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

2 Replies 2

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

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 pause for 30 seconds to allow the remote site to generate the response.

I then have a repeating FTP GET job which runs until it gets at which point it calls an action to cancel itself so I don't poll endlessly once I've got the file. This allows the remote site whatever time they need to create the file (anything from seconds to hours) but means I don't wait around unnecessarily or annoy the remote end by having a continuous poll going on throughout the day.

All good.

Cheers

Review Cisco Networking for a $25 gift card