Controlling external script invocations

When listing the files using a Kognitio external script running in a bash script environment, there’s somestimes no need to for multiple invocations of this script to be run. Particularly if combined with the “run on node” capability.

Example: bash script to list files in linux directory

This Kognitio external script RECEIVES a list of directory names (or folders) and outputs the files and directories contained within them. It uses the bash command ls. The script is limited to run only a single invocation to obtain only one list of files.

CREATE EXTERNAL SCRIPT list_files ENVIRONMENT bash
RECEIVES(directory VARCHAR(32000))
SENDS(filename VARCHAR(100))
LIMIT 1 THREADS
SCRIPT S'EOF(
        while read dir;
        do ls -a $dir
    done
)EOF';

To list the files in the root directory of the server where the script is invoked submit the SQL:

EXTERNAL SCRIPT list_files
FROM (SELECT '/')

The linux user wxextern (the default account Kognitio uses to execute external scripts) must have the required permissions on the system to list files in the root directory (‘/’).