我完全是初学者,我用谷歌搜索了一些 if elseif else 教程并开始构建这个脚本。我正在尝试创建一个 .sh 脚本,它让我可以选择从 PHP 脚本管理我的阀门源服务器。这是我目前拥有的:
#!/bin/sh
# CONFIG
LOGFILE="/var/www/management/ifacelog"
NEWDATE=`TZ=GMT-3 date +%d.%m.%Y" "%H:%M:%S`
# END OF CONFIG
SCRIPTCOMMAND=$1
CSGOCOMMAND=$2
if [ $SCRIPTCOMMAND = "START" ] ; then
echo $NEWDATE "SERVER STARTED! connect cs.kask.fi; password gd | rcon_password tuksu" >> test
touch lockfile
screen -A -m -d -S csgo -L /home/csgo/server/srcds_run -game csgo -console -usercon -tickrate 128 +net_public_adr 46.246.93.192 +ip 46.246.93.192 +tv_port 27010 -maxplayers_override 11 +game_type 0 +game_mode 1 +host_worksh$
elif [ $SCRIPTCOMMAND = "RESTART" ] ; then
echo $NEWDATE "STOPPING THE SERVER" >> test
echo $NEWDATE "Passing command tv_stoprecord and waiting 10sec." >> test
screen -S csgo -X stuff "tv_stoprecord"
screen -S csgo -X stuff "
"
sleep 10
echo $NEWDATE "Passing command: quit" >> test
screen -S csgo -X stuff "quit"
screen -S csgo -X stuff "
"
echo $NEWDATE "SERVER RESTARTED!" >> test
elif [ $SCRIPTCOMMAND = "KILL" ]; then
echo $NEWDATE "KILLING SERVER!" >> test
pkill srcds_run
rm lockfile
rm screenlog.0
elif [ $SCRIPTCOMMAND = "RCON" ]; then
echo $NEWDATE "REMOTE RCON! Passing value: " $2 $3 >> test
screen -X -S csgo -p 0 stuff $2 $3
screen -S csgo -X stuff "
"
elif [ $SCRIPTCOMMAND = "RESET" ]; then
rm lockfile
rm screenlog.0
else
echo "UNKNOWN COMMAND WAS PASSED!"
fi
除了将命令传递给屏幕会话本身(如果 scriptcommand = RCON)之外,一切正常。如果我输入 shell screen -X -S csgo -p 0 stuff say test
,它会正确地将其传递给屏幕会话。如果我运行我的脚本./csgo.sh RCON say test
,屏幕会显示错误-X: stuff: invalid option "say"
。我也尝试过,screen -X -S csgo -p 0 stuff \"$2\"
但这没有任何区别。
由于如果我手动键入它可以正常工作,我不知道为什么它不能在脚本上工作。知道为什么它不起作用以及如何解决它吗?