Browse Source

add send command to console (#2350)

* add send command

Added a function to send command directly to the console
If the user don't provide a command right after the "send" argument, he will be prompt to enter a command

* updates to messages

converted spaces to tabs

* minor

* minor

* messages only display if manual entry

* updated description

* send will not show if not supported

* corrected if changed to !

* ui updates

* ui changes

* Update core_getopt.sh

Co-authored-by: Daniel Gibbs <[email protected]>
Co-authored-by: Frisasky <[email protected]>
pull/3288/head
DUDU54 5 years ago
committed by GitHub
parent
commit
770f969afc
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 38
      lgsm/functions/command_send.sh
  2. 5
      lgsm/functions/core_functions.sh
  3. 6
      lgsm/functions/core_getopt.sh
  4. 14
      lgsm/functions/core_messages.sh
  5. 1
      linuxgsm.sh

38
lgsm/functions/command_send.sh

@ -0,0 +1,38 @@
#!/bin/bash
# LinuxGSM command_send.sh function
# Author: Duval Lucas
# Website: https://linuxgsm.com
# Description: Send command to the server tmux console.
local commandname="SEND"
local commandaction="Send"
local function_selfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
check.sh
if [ -z "${userinput2}" ]; then
fn_print_header
fn_print_information_nl "Send allows a command to be sent to the console."
fi
check_status.sh
if [ "${status}" != "0" ]; then
if [ -n "${userinput2}" ]; then
command_to_send="${userinput2}"
else
echo ""
command_to_send=$( fn_prompt_message "send: " )
fi
fn_print_dots "Sending command to console: \"${command_to_send}\""
tmux send-keys -t "${servicename}" "${command_to_send}" ENTER
fn_print_ok_nl "Sending command to console: \"${command_to_send}\""
fn_script_log_pass "Command \"${command_to_send}\" sent to console"
else
fn_print_error_nl "Server not running"
fn_script_log_error "Failed to access: Server not running"
if fn_prompt_yn "Do you want to start the server?" Y; then
exitbypass=1
command_start.sh
fi
fi
core_exit.sh

5
lgsm/functions/core_functions.sh

@ -180,6 +180,11 @@ functionfile="${FUNCNAME[0]}"
fn_fetch_function
}
command_send.sh(){
functionfile="${FUNCNAME}"
fn_fetch_function
}
# Checks
check.sh(){

6
lgsm/functions/core_getopt.sh

@ -23,6 +23,7 @@ cmd_test_alert=( "ta;test-alert" "command_test_alert.sh" "Send a test alert." )
cmd_monitor=( "m;monitor" "command_monitor.sh" "Check server status and restart if crashed." )
cmd_skeleton=( "sk;skeleton" "command_skeleton.sh" "Create a skeleton directory." )
cmd_donate=( "do;donate" "command_donate.sh" "Donation options." )
cmd_send=( "sd;send" "command_send.sh" "Send command to server console." )
# Console servers only.
cmd_console=( "c;console" "command_console.sh" "Access server console." )
cmd_debug=( "d;debug" "command_debug.sh" "Start server directly in your terminal." )
@ -85,6 +86,11 @@ currentopt+=( "${cmd_backup[@]}" )
# Console & Debug
currentopt+=( "${cmd_console[@]}" "${cmd_debug[@]}" )
# Exclude game servers that dont support send
if [ "${shortname}" != "rust" ]||[ "${shortname}" != "hw" ]||[ "${shortname}" != "ark" ]||[ "${shortname}" != "ts3" ]; then
currentopt+=( "${cmd_send[@]}" )
fi
## Game server exclusive commands.
# FastDL command.

14
lgsm/functions/core_messages.sh

@ -359,6 +359,20 @@ fn_prompt_yn(){
done
}
# Prompt for message
fn_prompt_message(){
local prompt="$1"
while true; do
read -e -p "${prompt}" -r answer
if fn_prompt_yn "\"${answer}\", is this correct ?" Y; then
break;
fi
done
echo "${answer}"
}
# On-Screen End of Line
##################################

1
linuxgsm.sh

@ -42,6 +42,7 @@ configdir="${lgsmdir}/config-lgsm"
configdirserver="${configdir}/${gameservername}"
configdirdefault="${lgsmdir}/config-default"
userinput="${1}"
userinput2="${2}"
## GitHub Branch Select
# Allows for the use of different function files

Loading…
Cancel
Save