Function Block FS_SHELL

The function block FS_SHELL executes one or more remote commands in an interactive shell.

Warning: System commands can endanger or damage the remote system. In addition, existing files may be overwritten without a warning.

The file system must have been initialized beforehand using FS_INIT. All operations are performed asynchronously per storage medium created.

Input RUN

A positive edge executes the specified command.

Input DEV

Defines the device from which files should be accessed. The device is used per project and can be managed in the context menu under Project External Storage.

Input PATH

Specifies the path to the directory on the storage medium. The path corresponds to a Unix file path in UTF-8 format, if this is supported. The path is represented as follows:

Folder/Subfolder

The use of a path is optional. If it has been set, changing to this directory must be successful; otherwise, the command to be executed will not be run.

Input CMD

Defines all commands that are to be executed. All commands must be terminated by an end-of-line character. For example: "ls\n". If no end-of-line character is used, the command will probably not be executed. The commands are executed line by line after feedback from the server.

After executing all commands, an "exit\n" should be sent at the end to immediately terminate the connection and return the values. No further command should then be sent, otherwise the output ERROR will be set to TRUE.

Note: If the connection is unexpectedly terminated and a command was not sent, the output ERROR will be set to TRUE.

Input PTY

Defines the type of console (Pseudo-Terminal). For some devices, this parameter is mandatory. Examples: "vanilla", "exec", "vt100", "vt102", "ansi", "xterm" etc. If no value is defined, "vanilla" will be used.

The value "exec" executes the request via SSH command from the operating system. This uses more modern methods. However, this method is somewhat less efficient. The input ENV is set before the connection, so it may be ignored. The input SIZE will be ignored with this method.

If additional SSH parameters need to be passed, they can each be added in a new line after "exec". The parameters are case-sensitive and specified as follows. This example enables the RSA algorithm for older devices.

exec
HostKeyAlgorithms=+ssh-rsa
PubkeyAcceptedAlgorithms=+ssh-rsa

The following parameters are available:

SSH Parameters for exec Example Value
KexAlgorithms +diffie-hellman-group1-sha1
Ciphers +aes128-cbc
HostKeyAlgorithms +ssh-rsa
PubkeyAcceptedAlgorithms +ssh-rsa
ConnectTimeout 10
ServerAliveInterval 30
ServerAliveCountMax 3

Note: For further details, see the external documentation: https://linux.die.net/man/5/ssh_config (English)

Input ENV

Defines the active environment variables. To specify multiple variables, one can be defined per line. Example:

LANG=en_US.UTF-8
LC_ALL=en_US.UTF-8

Input SIZE

Defines the size of the terminal. By default, this is specified in characters but can also be defined in pixels. For example: "80x25" or "640x480px". If no value is defined, "80x25" will be used.

Input RECV_PT

Defines a timeout for receiving data per command in the format T#. If no timeout is defined, T#150ms will be used. If this value is not high enough, multiple commands may be executed during data output.

Input TIMEOUT

Sets a timeout in the format T# for executing all commands. After reaching this, the connection will be terminated and the value returned. ERROR is set to TRUE. The timeout is evaluated after establishing the connection and authentication. If the input PTY has been set to "exec", the execution time will be evaluated for the entire period. If no timeout is defined, T#300s will be used.

Output DONE

The output returns a pulse on success to perform the next operation. The pulse occurs when the process ends, even if an error has occurred.

Output RETURN

Returns the command's return value upon successful execution. The value is stored for later use.

Note: Note that the console formats the output. This may also contain control characters or binary data.

Output RETERR

Returns the command's return value upon faulty execution. Also called STDERR with SSH. The value is stored for later use.

Note: Note that the console formats the output. This may also contain control characters or binary data.

Output ERROR

In case of an error, returns a text with an error message. This is FALSE if no error has occurred. The state is stored for later use.

Possible causes:

  • The service of the storage medium was not started.
  • The memory was not initialized.
  • The login credentials are invalid.
  • The remote server could not be reached.
  • The storage medium does not exist.
  • The specified path is invalid.
  • Writing to the storage medium is not possible.
  • No more memory space available on the storage or it is write-protected.
  • The connection was unexpectedly terminated before all commands could be sent.
  • The defined timeout was reached.

See Also