command_send.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. commandtosend=$(fn_prompt_message "send: ")
  23. fi
  24. echo ""
  25. fn_print_dots "Sending command to console: \"${commandtosend}\""
  26. fn_print_ok_nl "Sending command to console: \"${commandtosend}\""
  27. tmux -L "${socketname}" send-keys -t "${sessionname}" "${commandtosend}" ENTER
  28. fn_script_log_pass "Command \"${commandtosend}\" sent to console"
  29. else
  30. fn_print_error_nl "Server not running"
  31. fn_script_log_error "Failed to access: Server not running"
  32. if fn_prompt_yn "Do you want to start the server?" Y; then
  33. exitbypass=1
  34. command_start.sh
  35. fi
  36. fi
  37. core_exit.sh