Changeset 13 for scripts/usr/local/bin
- Timestamp:
- May 16, 2014, 2:13:55 PM (11 years ago)
- Location:
- scripts/usr/local/bin
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
scripts/usr/local/bin/7dtd-common.sh
r10 r13 1 1 #!/bin/bash 2 # Version 12 # Version 2 3 3 4 4 # Provides common functions for 7dtd-scripts. Not intended to be run directly. … … 52 52 } 53 53 54 # Get the PID of the instance if it is running, 0 otherwise 55 # Params: 56 # 1: Instance name 57 # Returns: 58 # 0 if not running 59 # PID otherwise 60 getInstancePID() { 61 run=$(isRunning $1) 62 if [ $run -eq 1 ]; then 63 cat $(getInstancePath $1)/7dtd.pid 64 else 65 echo 0 66 fi 67 } 68 54 69 # Get a single value from a serverconfig 55 70 # Params: -
scripts/usr/local/bin/7dtd-instances.sh
r11 r13 1 1 #!/bin/bash 2 # Version 12 # Version 2 3 3 4 4 # Lists available 7dtd instances. … … 9 9 checkRootLoadConf 10 10 11 printf "%-*s | %-*s | %-*s\n" 20 "Instance name" 8 "Running" 7 "Players" 12 printf -v line "%*s-+-%*s-+-%*s\n" 20 " " 8 " " 7 " " 13 echo ${line// /-} 14 for I in $SDTD_BASE/instances/*; do 15 ins=`basename $I` 16 run=$(isRunning $ins) 17 if [ $run -eq 1 ]; then 18 run="yes" 19 tel=$(telnetCommand $ins lp) 11 listInstances() { 12 printf "%-*s | %-*s | %-*s | %-*s\n" 20 "Instance name" 8 "Running" 7 "Players" 5 "Port" 13 printf -v line "%*s-+-%*s-+-%*s-+-%*s\n" 20 " " 8 " " 7 " " 5 " " 14 echo ${line// /-} 15 for I in $SDTD_BASE/instances/*; do 16 ins=`basename $I` 17 run=$(isRunning $ins) 18 if [ $run -eq 1 ]; then 19 run="yes" 20 tel=$(telnetCommand $ins lp) 21 cur=`echo $tel | sed "s/\r/\n/g" | sed "s/^ //g" | grep "Total of " | cut -d\ -f 3` 22 else 23 run="no" 24 cur=0 25 fi 26 27 max=$(getConfigValue $ins ServerMaxPlayerCount) 28 port=$(getConfigValue $ins ServerPort) 29 30 printf "%-*s | %*s | %2d/%2d | %5d\n" 20 "$ins" 8 "$run" $cur $max $port 31 done 32 exit 0 33 } 34 35 showInfo() { 36 if [ -z $1 ]; then 37 echo "Missing parameter <instance>" 38 exit 1 39 fi 40 checkInstance $1 41 42 line() { 43 printf " %-*s %s\n" 15 "$1" "$2" 44 } 45 46 echo 47 48 echo "7dtd instance: $1" 49 echo 50 51 res=$(isRunning $1) 52 if [ $res -eq 1 ]; then 53 echo "Status: Running" 54 echo "Open ports:" 55 netstat -nlp | grep $(getInstancePID $1) | sed -r 's/^([^ ]*)\s+.*[^ :]*:([^ ]*).*[^ :]*:[^ ]*.*/ \2 (\1)/g' | sort 56 tel=$(telnetCommand $1 lp) 20 57 cur=`echo $tel | sed "s/\r/\n/g" | sed "s/^ //g" | grep "Total of " | cut -d\ -f 3` 58 echo "Players: $cur" 21 59 else 22 run="no" 23 cur=0 60 echo "Status: NOT running" 24 61 fi 25 62 26 max=$(getConfigValue $ins ServerMaxPlayerCount) 27 28 printf "%-*s | %*s | %2d/%2d\n" 20 "$ins" 8 "$run" $cur $max 29 done 30 exit 0 63 echo 64 echo "Game info:" 65 line "Server name:" $(getConfigValue $1 ServerName) 66 line "Password:" $(getConfigValue $1 ServerPassword) 67 line "Max players:" $(getConfigValue $1 ServerMaxPlayerCount) 68 line "World:" $(getConfigValue $1 GameWorld) 69 70 echo 71 echo "Network info:" 72 line "Port:" $(getConfigValue $1 ServerPort) 73 line "Public:" $(getConfigValue $1 ServerIsPublic) 74 if [ "$(getConfigValue $1 ControlPanelEnabled)" = "false" ]; then 75 cp="off" 76 else 77 cp="Port $(getConfigValue $1 ControlPanelPort), Pass $(getConfigValue $1 ControlPanelPassword)" 78 fi 79 line "Control Panel:" "$cp" 80 if [ "$(getConfigValue $1 TelnetEnabled)" = "false" ]; then 81 tn="off" 82 else 83 tn="Port $(getConfigValue $1 TelnetPort), Pass $(getConfigValue $1 TelnetPassword)" 84 fi 85 line "Telnet:" "$tn" 86 87 echo 88 exit 0 89 } 90 91 showHelp() { 92 name=`basename $0` 93 echo "Unknown parameter: $1" 94 echo "Usage:" 95 echo " $name [list] - List all instances" 96 echo " $name show <instance> - Show detailed info on the given instance" 97 exit 0 98 } 99 100 COMMAND=${1:-list} 101 102 case "$COMMAND" in 103 list) 104 listInstances 105 ;; 106 show) 107 showInfo $2 108 ;; 109 *) 110 showHelp $COMMAND 111 esac 112 exit 1
Note:
See TracChangeset
for help on using the changeset viewer.