jscript, jtool script
A platform agent tool used to 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 given 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).
Syntax
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 | Show this help and exit. |
-l <loglevel> | Set the logging level. |
-f <logfile> | Log to file instead of stdout/stderr. |
-j, -job-context | Obtain environment from job-context. |
-i | Interactive, execution will not stop on successful execution of the first command. |
-s | Silent, suppress prompts and feedback (but not error messages). |
-t, -timeout | Timeout in seconds that jscript waits; default is set to 600 seconds (10 minutes) |
<connfile> | A file containing connection details, like host, port, username, and password. Required when -job-context is not specified. You 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 Settings
The following environment variables are used to retrieve proxy server connection details:
HTTP_PROXY
- The URL to the proxy server,https://proxy.example.com:3128
PROXY_USER
- The user for the proxy server, ignored ifHTTP_PROXY
is not setPROXY_PASSWORD
- The password for the proxy user, ignored ifHTTP_PROXY
is not setNO_PROXY
- Enforce a direct connection
note
These environment variables override the settings in the connection file.
Setting the Return Code
The jcsShell.setReturnCode(int)
method is used to set the return code of the script. You 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
- Perform an SQL query against the data model:- Supports formats
xml
,csv
, andhtml
. - Bind parameters are specified using the following syntax
bind <position> <dataType> <value>
.
- Supports formats
submit
- Submit a process:- Parameters are filled using the following syntax
parameter <parameter_name> <value>
. - Optionnally, you can set a timeout and status or
final
, for any final state; once either is reachedjscript
stops waiting. Accepts the following syntaxes:wait <milliseconds_to_wait> final
orwait <milliseconds_to_wait> status <status>
.
- Parameters are filled using the following syntax
Query Example
jscript> query
set format csv
bind 1 BigDecimal 5
bind 2 String '%Test%'
select count(*) from Job where JobId > ? and Description like ?
Submit Example
jscript> submit System_Sleep
parameter MilliSeconds 10000
wait 60000 final
Example
The following shows how we submit a process from a UNIX shell. In this example, 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; this improves the security of your password.
$ 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
The jscript
program can also read commands from a file as follows:
$ 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 perform the same but use the terminal to supply input you will see prompts:
$ 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
$