Striim 3.9.7 documentation

Calling a shell script from a custom Java function

The following custom function will call a shell script specified in TQL.

import com.webaction.runtime.compiler.custom.Nondeterministic; 
...

@Nondeterministic
public static int kickShell (String args) {
        int ret = 0;
        try {
            if (args.indexOf(".sh") == -1) {
                System.out.println("Error:" + args + " is not shell.");
                return ret;
            }
            Process process = new ProcessBuilder("sh", args).start();
            ret = process.waitFor();
            System.out.println("return:" + ret);
        }catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("Info: Please specify one argument.");
            System.out.println("return:" + ret);
        }catch (Exception e){
            System.out.println("return:" + ret);
            e.printStackTrace();
        }finally{
            return ret;
        }
    }

You could use that in TQL as follows:

CREATE CQ ...
SELECT kickShell('/etc/striim/test.sh') as retVal ...

import com.webaction.runtime.compiler.custom.Nondeterministic; and @Nondeterministic cause the script to be executed every time the CQ is run. Without those lines, the script would be called only once, on deployment.

Warning

Consider the potential security issues of allowing TQL applications to call scripts on the Striim host system. Depending on your environment and requirements, it may be more appropriate to call a specific script from the custom Java function.