Advertisement
Guest User

console.sh

a guest
Dec 7th, 2013
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.69 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. port="44400"
  4. host="localhost"
  5. rcon_passwd="<your_password>"
  6.  
  7. [ -n "$1" ] && port=$1
  8. [ -n "$2" ] && host=$1 && port=$2
  9.  
  10. send() {
  11.     echo -e "\xFF\xFF\xFF\xFFrcon ${rcon_passwd} $*\n\n" | nc -uq 1 ${host} ${port}
  12. }
  13.  
  14. check_connection() {
  15.     response=`send status`
  16.     [ "${response}" = "" ] && return 1 || return 0
  17. }
  18.  
  19. echo -n "$0: connecting... "
  20. if ! check_connection; then
  21.     echo -e "\n$0: can't connect to ${host}:${port}"
  22.     echo -e "usage: $0 [[<host>] <port>]"
  23.     exit 0
  24. fi
  25. echo -e "[ok]\n$0: press ^C or type \"quit\" to exit\n"
  26.  
  27. while true; do
  28.     IFS="" read -r -e -d $'\n' -p "> " cmd
  29.     [ "${cmd}" == "quit" ] && exit 0
  30.     send ${cmd} | tail -n+3
  31.     history -s "${cmd}"
  32. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement