bash:使这个脚本允许执行php解析器

时间:2011-05-18 11:19:32

标签: php bash shell

目前我使用以下脚本启动Armagetron服务器

#!/bin/sh

tron="/home/duke/aa/bin/armagetronad-dedicated"
var="/home/duke/aa/servers/demo/var/"
log="${var}console_log.txt"
userconfigdir="/home/duke/aa/servers/demo/var/customize/config/"
parser="/home/duke/aa/scripts/parser.php"
ladderlog="${var}ladderlog.txt"
cmds="${var}cmd.txt"

tail -n0 -f -s 0.01 $ladderlog | $parser | $tron --userconfigdir $userconfigdir --vardir $var | tee -a $log

这会运行服务器并在$ parser中应用php脚本

但是,我想像这样启动我的服务器:

#!/bin/bash
    screen -S $1 -X quit    # avoiding to run the same server twice
screen -dmS $1 /home/duke/aa/scripts/srv $1     

SRV:

screen -S $1 -X logtstamp on 
screen -S $1 -X logfile /home/duke/aa/servers/$1/logs
screen -S $1 -X log on 
while true; do  # start a loop to allow server restart if it crashes
/home/duke/aa/bin/armagetronad-dedicated --vardir /home/duke/aa/servers/$1/var  --userdatadir /home/duke/aa/servers/$1/var/customize #run the server    

    echo "###Server has crashed. Ctrl-C to cancel reboot...###"
    sleep 5

done # end the loop

这里唯一的问题是我不知道如何指定在服务器上运行的php解析器(即使是菜鸟)。我如何修改第二个脚本以允许这个?

1 个答案:

答案 0 :(得分:1)

将第一个块中的所有代码放在srv脚本中的while循环中,即

SRV:

#!/bin/bash
tron="/home/duke/aa/bin/armagetronad-dedicated"
var="/home/duke/aa/servers/demo/var/"
log="${var}console_log.txt"
userconfigdir="/home/duke/aa/servers/demo/var/customize/config/"
parser="/home/duke/aa/scripts/parser.php"
ladderlog="${var}ladderlog.txt"
cmds="${var}cmd.txt"


screen -S $1 -X logtstamp on 
screen -S $1 -X logfile /home/duke/aa/servers/$1/logs
screen -S $1 -X log on 
while true; do  # start a loop to allow server restart if it crashes
    tail -n0 -f -s 0.01 $ladderlog | $parser | $tron --userconfigdir $userconfigdir --vardir $var | tee -a $log
    # /home/duke/aa/bin/armagetronad-dedicated --vardir /home/duke/aa/servers/$1/var  --userdatadir /home/duke/aa/servers/$1/var/customize #run the server  

    echo "###Server has crashed. Ctrl-C to cancel reboot...###"
    sleep 5

done # end the loop

(这看起来不错吗?)

我希望这会有所帮助。