Showing results for 
Search instead for 
Did you mean: 

execute command from trafficscript

New Contributor

execute command from trafficscript

is there a way to execute a system command from within trafficscript?

For example. If i wanted to place a message on to message bus based on an event triggered in a trafficscript rule. i may want to 

  1. @args = ("/usr/bin/msgq", "arg1", "arg2");
  2.    system(@args) == 0
  3.   or die "system @args failed: $?"

But i cant see system() or exec() within the trafficscript documentation.

I note i can run arbitrary commands for other "events", but rules appear to be TS only.

Please advise.

Frequent Contributor

Re: execute command from trafficscript


     There is no direct way to make a system call to execute something from TrafficScript equivalent to system() or exec functions in other languages..

There are some ways in which functionality like this can be emulated but with a few caveats:

1) "Non blocking ONE-WAY" execution (ie: one where the output of the executed event cannot be processes) in a "fire and forget" fashion. This is useful for a custom alert program that something happened.

  • Using the TrafficScript function event.emit() you can trigger a customised event that can then have an action associated with it under system > alerting to trigger an executable script uploaded to the STM "Extra Files" section (under Catalogs > Extrafiles)

2) "A Blocking Interactive" execution (ie: one where the output of the executed event can be processed). This is useful if the output of the execution needs to be processed:

  • Using the http.request.*() TrafficScript functions, an interactive http request can be issued to a remote HTTP server that executes the needed code (maybe as a GCI-BIN for example) and returns the appropriate data/value that the TrafficScript can then parse appropriately. Be aware that the http.request.*() functions cannot be used in completion rules.
  • Using the TrafficScript function to execute a custom Java Applet on the STM. Be aware that can only be used with TCP-based protocols and cannot be used in completion rules.

Does this help?



Aidan Clarke
Pulse Secure vADC Product Manager