command_send.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/bash
  2. # LinuxGSM command_send.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: https://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Send command to the server tmux console.
  7. commandname="SEND"
  8. commandaction="Send"
  9. moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  10. fn_firstcommand_set
  11. check.sh
  12. if [ -z "${userinput2}" ]; then
  13. fn_print_header
  14. fn_print_information_nl "Send a command to the console."
  15. fi
  16. check_status.sh
  17. if [ "${status}" != "0" ]; then
  18. if [ -n "${userinput2}" ]; then
  19. commandtosend="${userinput2}"
  20. else
  21. echo ""
  22. if ! commandtosend=$(fn_prompt_message "send: "); then
  23. echo -e ""
  24. fn_print_error_nl "Unable to read a command to send: no input available"
  25. fn_script_log_error "Unable to read a command to send: no input available"
  26. # shellcheck disable=SC2034 # Used by core_exit.sh.
  27. exitcode=2
  28. core_exit.sh
  29. fi
  30. fi
  31. echo ""
  32. fn_print_dots "Sending command to console: \"${commandtosend}\""
  33. fn_print_ok_nl "Sending command to console: \"${commandtosend}\""
  34. TERM=screen tmux -L "${socketname}" send-keys -t "${sessionname}" -l "${commandtosend}"
  35. TERM=screen tmux -L "${socketname}" send-keys -t "${sessionname}" ENTER
  36. fn_script_log_pass "Command \"${commandtosend}\" sent to console"
  37. else
  38. fn_print_error_nl "Unable to send command to console. Server not running"
  39. fn_script_log_error "Unable to send command to console. Server not running"
  40. fi
  41. core_exit.sh