Skip to content

Platform Functionality

🛠️ Tools · ⬅ Home


Execution

executableExists

Does a binary exist in the PATH?

Usage

executableExists [ --any ] binary ... [ --help ]

Does a binary exist in the PATH?

Arguments

  • --any - Flag. Optional. If any binary exists then return 0 (success). Otherwise, all binaries must exist.
  • binary ... - String. Required. One or more Binaries to find in the system PATH.
  • --help - Flag. Optional. Display this help.

Examples

executableExists cp date aws ls mv stat || throwEnvironment "$handler" "Need basic environment to work" || return $?
executableExists --any terraform tofu || throwEnvironment "$handler" "No available infrastructure providers" || return $?
executableExists --any curl wget || throwEnvironment "$handler" "No way to download URLs easily" || return $?

Return codes

  • 0 - If all values are found (without the --any flag), or if any binary is found with the --any flag
  • 1 - If any value is not found (without the --any flag), or if all binaries are NOT found with the --any flag.

Requires

throwArgument decorate __decorateExtensionEach command

runCount

Run a binary count times

Usage

runCount [ count ] [ binary ] [ args ... ]

Run a binary count times

Arguments

  • count - The number of times to run the binary
  • binary - The binary to run
  • args ... - Any arguments to pass to the binary each run

Return codes

  • 0 - success
  • 2 - count is not an unsigned number
  • Any - If binary fails, the exit code is returned

bashMakeExecutable

Makes all *.sh files executable

Usage

bashMakeExecutable [ --find findArguments ] [ path ... ]

Makes all *.sh files executable

Arguments

  • --find findArguments - String. Optional. Add arguments to exclude files or paths. SPACE-delimited for multiple options.
  • path ... - Directory. Optional. One or more paths to scan for shell files. Uses PWD if not specified.

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

Environment

  • Works from the current directory

Memory

Usage

processMemoryUsage pid

Outputs value of resident memory used by a process, value is in kilobytes

Arguments

  • pid - Integer. Required. Process ID of running process

Examples

> processMemoryUsage 23

Sample Output

423

Return codes

  • 0 - Success
  • 2 - Argument error

Usage

processVirtualMemoryAllocation [ --help ] [ pid ]

Outputs value of virtual memory allocated for a process, value is in kilobytes

Arguments

  • --help - Flag. Optional. Display this help.
  • pid - Process ID of running process

Examples

processVirtualMemoryAllocation 23

Sample Output

423

Return codes

  • 0 - Success
  • 2 - Argument error

CPU

cpuCount

Return integer count of CPUs on this system

Usage

cpuCount [ --handler handler ] [ --help ]

Return integer count of CPUs on this system

Writes to standard output

PositiveInteger

Arguments

  • --handler handler - Function. Optional. Use this error handler instead of the default error handler.
  • --help - Flag. Optional. Display this help.

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

loadAverage

Get the load average using uptime

Usage

loadAverage [ --help ]

Get the load average using uptime

Writes to standard output

lines:Number

Arguments

  • --help - Flag. Optional. Display this help.

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

Requires

uptime

Services

serviceToPort

Get the port number associated with a service

Usage

serviceToPort service [ --services servicesFile ] [ --help ]

Get the port number associated with a service

Arguments

  • service - String. Required. A unix service typically found in /etc/services
  • --services servicesFile - File. Optional. File like '/etc/services`.
  • --help - Flag. Optional. Display this help.

Sample Output

Port number of associated service (integer) one per line

Return codes

  • 1 - service not found
  • 2 - bad argument or invalid port
  • 0 - service found and output is an integer

serviceToStandardPort

Hard-coded services for:

Usage

serviceToStandardPort [ --help ] [ service ... ]

Hard-coded services for: - ssh -> 22 - http-> 80 - https-> 80 - postgres-> 5432 - mariadb-> 3306 - mysql-> 3306 Backup when /etc/services does not exist.

Arguments

  • --help - Flag. Optional. Display this help.
  • service ... - String. Optional. A unix service typically found in /etc/services

Sample Output

Port number of associated service (integer) one per line

Return codes

  • 1 - service not found
  • 0 - service found and output is an integer

Users

Usage

userHome [ pathSegment ]

The current user HOME (must exist) No directories should be created by calling this, nor should any assumptions be made about the ability to read or write files in this directory.

Arguments

  • pathSegment - String. Optional. Add these path segments to the HOME directory returned. Does not create them.

Return codes

  • 1 - Issue with buildEnvironmentGet HOME or $HOME is not a directory (say, it's a file)
  • 0 - Home directory exists.

Usage

userRecord index [ user ] [ database ]

Look user up, output a single user database record.

Writes to standard output

String. Associated record with index and user.

Arguments

  • index - PositiveInteger. Required. Index (1-based) of field to select.
  • user - String. Optional. User name to look up. Uses whoami if not supplied.
  • database - File. Optional. User name database file to examine. Uses /etc/passwd if not supplied.

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

Requires

grep cut returnMessage printf /etc/passwd whoami

Usage

userRecordHome [ user ] [ database ]

Look user up, output user home directory

Writes to standard output

Directory. The user home directory.

Arguments

  • user - String. Optional. User name to look up. Uses whoami if not supplied.
  • database - File. Optional. User name database file to examine. Uses /etc/passwd if not supplied.

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

Usage

userRecordName [ user ] [ database ]

Look user up, output user name

Writes to standard output

the user name

Arguments

  • user - String. Optional. User name to look up. Uses whoami if not supplied.
  • database - File. Optional. User name database file to examine. Uses /etc/passwd if not supplied.

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

Groups

Usage

groupID groupName

Convert a group name to a group ID

Writes to standard output

Integer. One line for each group name passed as an argument.

Arguments

  • groupName - String. Required. Group name to convert to a group ID

Return codes

  • 0 - All groups were found in the database and IDs were output successfully
  • 1 - Any group is not found in the database.
  • 2 - Argument errors (blank argument)

Requires

throwArgument getent cut printf usageDocument decorate grep quoteGrepPattern