jscript, jtool script

jscript lets you execute RedwoodScript commands from the command line. This tool uses a connection file, and operation is synchronous. The script is executed the moment it receives an execute command.

Commands are always read from standard input. If standard input is a terminal and the silent option has not been set, a prompt will be shown. If standard input is a (redirected) file, pipe, or stream, no prompt is shown. If you use the -s option, the only output will be that sent by the server. This consists of user-created output via jcsOut and jcsErr, as well as errors thrown by the interpreter (which go to stderr).

Note: For installation instructions, see jtool.

Syntax

Copy
jscript  [-h|-?|-help] [-l <loglevel>] [-f <logfile>] -j|-job-context|<connfile>
         [-i|-interactive] [-s|-silent] [-m|-message-server]
         [-t|-timeout <seconds>] [-protect]

Argument Description
-h, -?, -help Shows the help.
-l <loglevel> Sets the log level.
-f <logfile> Logs to a file instead of stdout and stderr.
-j, -job-context Gets the environment from the job context.
-i Interactive. Execution will not stop on successful execution of the first command.
-s Silent. Suppresses prompts and feedback (but not error messages).
-t, -timeout Timeout in seconds for jscript. Defaults to 600 seconds.
<connfile> A file containing connection details, such as host, port, username, and password. Required when -job-context is not specified. You can generate this file with jsecret -c.

TLS Arguments

The arguments require the -protect argument.

Argument Environment Variable Description
-tlsv1_3, -tls13 JCS_SSL_METHOD=tlsv1_3 Use TLS v1.3 secured connection.
-tlsv1_2, -tls12 JCS_SSL_METHOD=tlsv1_2 Use TLS v1.2 secured connection.
-tlsv1_1, -tls11 JCS_SSL_METHOD=tlsv1_1 Use TLS v1.1 or better secured connection.
-tlsv1, -tls JCS_SSL_METHOD=tlsv1 Use TLS v1.0 or better secured connection (default).
-sslv3, -ssl JCS_SSL_METHOD=sslv3 Use SSL v3 or better secured connection.
-cipherlist <text> JCS_SSL_CIPHERLIST Set list of available ciphers.
-passphrase <text> JCS_SSL_PASSPHRASE Set passphrase for private key.
-key <file> JCS_SSL_KEYPATH Set private key.
-cert <file> JCS_SSL_CERTIFICATE_PATH Set public certificate.
-ca <file|path> JCS_SSL_TRUSTED_CERTIFICATE_FILE Trusted CA certificates path or file.
-[no]verify JCS_SSL_VERIFY_CERT (Do not) verify peer (server or client) certificate.
-verify-names <namelist> JCS_SSL_VERIFY_SERVER_NAMES, JCS_SSL_VERIFY_CLIENT_NAMES Verify peer (server or client) certificate hostname against list.

Proxy Setting Environment Variables

The following environment variables are used to retrieve proxy server connection details.

  • HTTP_PROXY: The URL of the proxy server. For example: https://proxy.example.com:3128.
  • PROXY_USER: The user for the proxy server. This value is ignored if HTTP_PROXY is not set.
  • PROXY_PASSWORD: The password for the proxy user. This value is ignored if HTTP_PROXY is not set.
  • NO_PROXY: Enforces a direct connection.

These environment variables override the settings in the connection file for all tools that connect to the central Redwood server.

Setting the Return Code

The jcsShell.setReturnCode(int) method is used to set the return code of the script. Throw an exception if you want to terminate processing. The last effective call to jcsShell.setReturnCode() will set the return code.

Buit-in Commands

The following built-in commands are available in jscript.

  • query: Performs an SQL query against the data model.
    • Supports formats xml, csv, and html.
    • Bind parameters are specified using the following syntax: bind <position> <dataType> <value>.
  • submit: Submits a Process Definition.
    • Supply parameters with the following syntax: parameter <parameter_name> <value>.
    • Optionally, set a timeout and status or final for any final state. Once either is reached, jscript stops waiting. This command accepts the following syntaxes: wait <milliseconds_to_wait> final or wait <milliseconds_to_wait> status <status>.

Query Example

Copy
jscript> query
set format csv
bind 1 BigDecimal 5
bind 2 String '%Test%'
select count(*) from Job where JobId > ? and Description like ?

Submit Example

Copy
jscript> submit System_Sleep
parameter MilliSeconds 10000
wait 60000 final

Submit Process Example

The following example shows how to submit a process from a UNIX shell. The Redwood Server is named pr1.example.com, its port is 50000, and the context is /redwood. Note, that when you enter your password for the connection file, no text is displayed as you type.

Copy
$ jsecret -c ../../net/instance/default/example.conn https://pr1.example.com:50000/redwood
Username:jdoe
Password:

$ jscript ../../net/instance/default/example.conn <<EOF
{
  JobDefinition jDefinition = jcsSession.getJobDefinitionByName("System_Info");
  Job process = jDefinition.prepare();
  jcsSession.persist();
}
/
EOF

jscript can also read commands from a file.

Copy
$ cat script.rws
{
  JobDefinition jDefinition = jcsSession.getJobDefinitionByName("System_Info");
  Job process = jDefinition.prepare();
  jcsSession.persist();
}
/
$ jscript ../../net/instance/default/example.conn < script.rws

If you run the same command but use the terminal to supply input, you will see prompts.

Copy
$ jscript ../../net/instance/default/example.conn
Connected to example
jscript> {
      2>   JobDefinition jDefinition = jcsSession.getJobDefinitionByName("System_Info");
      3>   Job process = jDefinition.prepare();
      4>   jcsSession.persist();
      5> }
      6> /
Result: OK
$