bash - Passing commands to named screen session via .sh script -
i'm beginner this, googled if elseif else tutorial , started build script. i'm trying create .sh script gives me option manage valves sourceserver php script. have currently:
#!/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" ] ; 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" ] ; echo $newdate "stopping server" >> test echo $newdate "passing command tv_stoprecord , 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" ]; echo $newdate "killing server!" >> test pkill srcds_run rm lockfile rm screenlog.0 elif [ $scriptcommand = "rcon" ]; 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" ]; rm lockfile rm screenlog.0 else echo "unknown command passed!" fi
everything working except passing commands screen session (if scriptcommand = rcon). if type in shell screen -x -s csgo -p 0 stuff test
, passes screen session properly. if run script ./csgo.sh rcon test
, screen says error -x: stuff: invalid option "say"
. tried screen -x -s csgo -p 0 stuff \"$2\"
didn't make difference.
since works fine if type manually, have no idea why doesn't work on script. idea why doesn't work , how fix it?