Adauga user cu comanda:
* Unde
username este numele de la user.
Te loghezi ca user dupa care creezi un script ex:
script.sh
* Poti folosi acest script, sa faci unele modificari dupa datele tale.
- script | Afiseaza codul
#!/bin/sh
# Server configuration
GAME='CS16 Server'
HRUN='hlds_run'
RUN='hlds_run -console +servercfgfile server.cfg -game cstrike -debug +maxplayers 32 +map de_dust2 +port 27015' #Start command
CMD='hlds_i686'
start()
{
if pgrep -u $USER -f $CMD > /dev/null;then
echo "[ WARNING! ] Server is currently running!"
sleep 1
echo "[ info ] Use: {stop|restart|status}"
else
cd $HOME
echo "Starting the $GAME Server..."
taskset -c 0 screen -A -m -d -S $USER ./$RUN
sleep 6
fi
}
stop()
{
if pgrep -u $USER -f $CMD > /dev/null;then
echo "Stopping $GAME Server..."
kill $(pgrep -u $USER -f $HRUN)
sleep 3
echo "Done. Service stop!"
else
echo "[ WARNING! ] Server is not running!"
fi
}
status()
{
if pgrep -u $USER -f $CMD > /dev/null;then
echo "[ Online ] Server is currently running!"
else
echo "[ Offline ] Server seems to have died"
fi
}
console()
{
if pgrep -u $USER -f $HRUN > /dev/null;clear
then
echo "$USER Connecting to $HOSTNAME"
echo " For exit from console press Ctrl + A,D"
echo " Dont press Ctrl+C"
echo " Please wait..."
sleep 3
while true; do
read -p "Please press [Y/n]: to connect console (y=yes,n=no): " yn
case $yn in
[Yy]* ) screen -d -r $(pgrep -u $USER -f "SCREEN -A -m -d -S $USER ./$HRUN");echo "Exit success, screen";exit;;
[Nn]* ) echo "Abort.";exit;;
* ) echo "Please answer yes or no!";;
esac
done
else
echo "[ Offline ] Server seems to have died"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 1
start
;;
status)
status
;;
console)
console
;;
*)
echo "[ info ] Use: {start|stop|restart|status|console}"
;;
esac
Il faci executabil:
Pentru comenzi folosesti
./script.sh start (pentru start)
Have fun :)>-
Stay chill.