Changeset 46 for scripts


Ignore:
Timestamp:
Jun 3, 2014, 8:01:56 PM (11 years ago)
Author:
alloc
Message:

Telnet command fix

Location:
scripts/usr/local/lib/7dtd
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • scripts/usr/local/lib/7dtd/commands/stop.sh

    r25 r46  
    3232
    3333                echo "Trying to gracefully shutdown..."
    34                 tmp=$(telnetCommand $1 shutdown)
     34                tmp=$(telnetCommand $1 shutdown "0.5")
    3535                echo "Waiting for server to shut down..."
    3636       
  • scripts/usr/local/lib/7dtd/common.sh

    r25 r46  
    151151#   1: Instance name
    152152#   2: Command
     153#   3: (Optional) Timeout in sec, defaulting to 1
    153154# Returns:
    154155#   String of telnet output
     
    158159        local TEL_PASS=$(getConfigValue $1 TelnetPassword)     
    159160        if [ "$TEL_ENABLED" = "true" ] && [ -n "$TEL_PASS" ]; then
    160                 echo -e "$TEL_PASS\n$2\nexit" | nc -q 2 127.0.0.1 $TEL_PORT
     161                local TEMPFILE=$(mktemp)
     162                rm -f $TEMPFILE
     163                mkfifo $TEMPFILE
     164                exec 3<> $TEMPFILE
     165                nc 127.0.0.1 $TEL_PORT <&3 &
     166                local NCPID=$!
     167                printf "$TEL_PASS\n$2\n" >&3
     168                sleep ${3:-1}
     169                printf "exit\n" >&3
     170                sleep 0.2
     171                kill -9 $NCPID > /dev/null 2>&1
     172                exec 3>&-
     173                rm -f $TEMPFILE
    161174        else
    162175                echo "Telnet not enabled or no password set."
Note: See TracChangeset for help on using the changeset viewer.