Remote
Shell
Commands
Executor
The RemoteShellCommandsExecutor class
is used to execute the bash commands on a remote host using the SSH as way to
communicate
Author
N7ghtm4r3 - Tecknobit
See also
Constructors
Properties
Link copied to clipboard
BASH_SCRIPT_OPTION the bash
option used to launch a script
Link copied to clipboard
EXEC_CHANNEL_TYPE exec type
of the channel used to execute the commands
Link copied to clipboard
EXECUTE_BASH_SCRIPT
bash command to execute a script
Link copied to clipboard
FIND_SERVICE_PATH the bash
command used to find the path of a service inside the
filesystem of the host
Link copied to clipboard
private val GET_BROADCAST_IP_ADDRESS_COMMAND: String = "ip -4 addr show | grep -E 'inet .*brd' | awk '{print $4}'"
GET_BROADCAST_IP_ADDRESS_COMMAND
bash command used to retrieve the broadcast ip address of
the network interface used to execute the Wake-on-Lan start
Link copied to clipboard
protected val GET_CURRENT_HOST_STATS: String = "echo -e "$(top -bn1 | grep 'Cpu(s)' | awk '{print 100 - $8}'),
$(if ls /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq &>/dev/null; then
freq=$(awk '{s+=$1} END {print s/NR/1000000}' /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq);
printf "%.2f" $freq;
else
freq=$(lscpu | grep 'CPU MHz' | awk '{print $3/1000}');
printf "%.2f" $freq;
fi),
$(free -b | awk '/Mem:/ {printf "%.2f/%.2f\n", $3/1073741824, $2/1073741824}'),
$(df --block-size=1G --total | awk '/total/ {printf "%d/%d\n", $3, $2}'),
$(if lsblk -d -o NAME | grep -q mmcblk; then echo "SD_CARD";
elif lsblk -d -o NAME | grep -q nvme; then echo "SSD_NVMe";
elif lsblk -d -o NAME | grep -q vda; then echo "VIRTUAL_DISK";
elif lsblk -d -o ROTA | awk 'NR>1' | grep -q 0; then echo "SSD";
else echo "HARD_DISK"; fi)"
"
GET_CURRENT_HOST_STATS
the bash command used to retrieve the current stats of the
physical machine of the host
Link copied to clipboard
private val GET_MAC_ADDRESS_COMMAND: String = "ip link show | awk -F': ' '/^[0-9]+: e/{print $2}' | head -n 1 | xargs -I {} ip link show {} | awk '/ether/ {print $2}'"
GET_MAC_ADDRESS_COMMAND
bash command used to retrieve the mac address of the network
interface used to execute the Wake-on-Lan start
Link copied to clipboard
protected val GREP_RUNNING_SERVICES_COMMAND: String = " ps -ef | grep -E %s | grep -v grep | awk '{print $2}' | paste -sd ','
"
GREP_RUNNING_SERVICES_COMMAND
the bash command used to retrieve all the running services
on a host and format their pids as list comma separated
Link copied to clipboard
KILL_SERVICE the bash command
used to kill a service currently running on the host
Link copied to clipboard
NOHUP_OUT_FILE the pathname
of the generated nohup.
Link copied to clipboard
PIPE_CHARACTER constant value
for the pipe character
Link copied to clipboard
REMOVE_FILE_COMMAND
the bash command used to remove a file from the filesystem
of the host
Link copied to clipboard
REMOVE_NOHUP_OUT_FILE_COMMAND
the bash command used to remove the NOHUP_OUT_FILE
from the host
Link copied to clipboard
SERVICE_STARTER_SCRIPT
the pathname of the script used to start the services
Link copied to clipboard
STRICT_HOST_KEY_CHECKING_OPTION
strict host key checking option
Link copied to clipboard
SUDO_REBOOT
the bash command used to reboot the physical machine of the
host
Link copied to clipboard
SUDO_SHUTDOWN_NOW the bash
command used to shut down the physical machine of the host
Functions
Link copied to clipboard
Method used to append the exit status of the
command to the error result of the same command
Link copied to clipboard
Method used to detect the stopped services
Link copied to clipboard
protected open fun execBashCommand(command: String, onCommandExecuted: ShellCommandsExecutor.OnCommandExecuted, closeSession: Boolean): String
protected open fun execBashCommand(command: String, onCommandExecuted: ShellCommandsExecutor.OnCommandExecuted): String
Method used to execute a bash command
Link copied to clipboard
Method used to execute the SERVICE_STARTER_SCRIPT
script
Link copied to clipboard
Method used to extract from the shell result
the pid of the started process
Link copied to clipboard
Method to find the path of the service using
the
FIND_SERVICE_PATH
command
Link copied to clipboard
Method used to get the current stats of the
host with the GET_CURRENT_HOST_STATS
command
Link copied to clipboard
Method used to obtain a specific instance to
correctly execute bash commands on hosts shells
Link copied to clipboard
Method to retrieve the network interface
details useful to execute the Wake-on-Lan
Link copied to clipboard
Method used to purge the NOHUP_OUT_FILE
when required
Link copied to clipboard
Method used to reboot the host using the SUDO_REBOOT
command
Link copied to clipboard
open fun rebootService(service: BrownieHostService, onCommandExecuted: ShellCommandsExecutor.OnCommandExecuted)
Method used to reboot a service
Link copied to clipboard
Method to simply remove a service from a
host
Link copied to clipboard
Method used to start a service
Link copied to clipboard
Method used to stop the host using the SUDO_SHUTDOWN_NOW
command
Link copied to clipboard
Method used to stop a service