Jump to content

tRolex

New Members
  • Posts

    9
  • Joined

  • Last visited

tRolex's Achievements

Member

Member (2/5)

1

Reputation

  1. hehe I managed to fix it by changing bash script colors <span style="color:blue"> this instead of $GREEN and now the output is as it should be
  2. So it would be easier to convert this bash script to php
  3. If you refresh or check my last quote you can see my (php code) which has to be rewritten in the right way.
  4. I would like to make a script where admins can "start, restart" a game server "FiveM" this is the link of the script above: http://www.thebalkanrp.tk/start.php <-- My bash "start,restart" script looks like this: #!/bin/bash WIT="\033[0;39m" ROOD="\033[1;31m" GROEN="\033[1;32m" GEEL="\033[1;33m" PAARS="\033[1;35m" LOL="\033[1;36m" MSG_180="Une temp.te approche, dans 3 minutes la ville sera rasé !" MSG_60="Une temp.te est aux portes de la ville, fuyez pauvres fous !" MSG_30="Mon dieu !! Dans 30 secondes vous serez tous morts si vous ne fuyez pas !" FIVEM_PATH=/home/thebalk/FiveM SCREEN="TheBalkanRP-SRV01-test" cd $FIVEM_PATH running(){ if ! screen -list | grep -q "$SCREEN" then return 1 else return 0 fi } case "$1" in # -----------------[ Start ]----------------- # start) if ( running ) then echo -e "" echo -e "$LOL BOT:$GROEN $SCREEN $ROOD SERVER IS ALREADY RUNNING!! $WIT" echo -e "" echo -e "$LOL BOT:$PAARS STOP THE SERVER FIRST: $GEEL./manage.sh stop $WIT" echo -e "$LOL BOT:$WIT OR" echo -e "$LOL BOT:$PAARS RESTART SERVER: $GEEL./manage.sh restart $WIT" sleep 2 else echo -e "" echo -e "$LOL BOT:$WIT STARTING THE GTA V SERVER " screen -dm -S $SCREEN sleep 2 screen -x $SCREEN -X stuff "cd /home/thebalk/FiveM/server-data && bash /home/thebalk/FiveM/run.sh +exec server.cfg " sleep 20 screen -x $SCREEN -X stuff "restart sessionmanager " echo -e "$LOL BOT:$GROEN SERVER HAS STARTED $WIT" sleep 2 fi ;; # -----------------[ Stop ]------------------ # stop) if ( running ) then echo -e "" echo -e "$LOL BOT:$WIT STOPPING THE GTA V SERVER" screen -S $SCREEN -p 0 -X stuff "`printf "say $MSG_30\r"`";sleep 10 screen -S $SCREEN -X quit sleep 5 echo -e "$LOL BOT:$WIT THE $GROEN $SCREEN $WIT SERVER HAS STOPPED" sleep 5 echo -e "$LOL BOT:$WIT REMOVING CACHE FOLDER" rm -R /home/thebalk/FiveM/server-data/cache/ sleep 5 echo -e "$LOL BOT:$ROOD CACHE FOLDER HAS BEEN REMOVED $WIT" sleep 5 echo -e "$LOL BOT:$ROOD THE $GROEN $SCREEN SERVER $ROOD HAS STOPPED $WIT" sleep 2 else echo -e "" echo -e "$LOL BOT:$ROOD THE $GROEN $SCREEN SERVER $ROOD IS NOT RUNNING!!! $WIT" echo -e "" echo -e "$LOL BOT:$PAARS USE THE COMMAND: $GEEL./manage.sh start $WIT" sleep 2 fi ;; # ----------------[ Restart ]---------------- # restart) if ( running ) then echo -e "" echo -e "$LOL BOT:$WIT THE $GROEN $SCREEN SERVER $WIT WAS RUNNING" sleep 5 echo -e "$LOL BOT:$WIT STOPPING THE $GROEN $SCREEN SERVER" screen -S $SCREEN -p 0 -X stuff "`printf "say $MSG_30\r"`"; sleep 10 screen -S $SCREEN -X quit sleep 5 echo -e "$LOL BOT:$WIT GTA V SERVER HAS STOPPED " sleep 5 echo -e "$LOL BOT:$WIT REMOVING CACHE FOLDER" rm -R /home/thebalk/FiveM/server-data/cache/ sleep 5 echo -e "$LOL BOT:$ROOD CACHE FOLDER HAS BEEN REMOVED $WIT" sleep 5 echo -e "$LOL BOT:$WIT STARTING THE $GROEN $SCREEN $WIT SERVER" screen -dm -S $SCREEN sleep 5 screen -x $SCREEN -X stuff "cd /home/thebalk/FiveM/server-data && bash /home/thebalk/FiveM/run.sh +exec server.cfg " sleep 20 screen -x $SCREEN -X stuff "restart sessionmanager " else echo -e "" echo -e "$LOL BOT:$WIT THE $GROEN $SCREEN SERVER $WIT IS NOT RUNNING" sleep 5 echo -e "$LOL BOT:$WIT STARTING THE $GROEN $SCREEN $WIT SERVER " screen -dm -S $SCREEN sleep 5 screen -x $SCREEN -X stuff "cd /home/fivem/FiveM/server-data && bash /home/fivem/FiveM/run.sh +exec server.cfg " sleep 20 screen -x $SCREEN -X stuff "restart sessionmanager " fi echo -e "$LOL BOT:$GROEN SERVER HAS STARTED $WIT" sleep 2 ;; # -----------------[ Status ]---------------- # status) if ( running ) then echo -e "$GROEN THE $LOL $SCREEN $GROEN SERVER IS RUNNING $WIT" else echo -e "$ROOD THE $LOL $SCREEN $ROOD SERVER IS NOT RUNNING $WIT" fi ;; # -----------------[ Screen ]---------------- # screen) echo -e "$GROEN Server screen [$SCREEN]. $WIT" screen -R $SCREEN ;; *) echo -e "$GEEL Use: $WIT ./manage.sh {start|stop|status|screen|restart}" exit 1 ;; esac exit 0 And I would like colourized output of the script when I run http://www.thebalkanrp.tk/start.php start.php should look something like:) <?php $cmd = '/home/thebalk/FiveM/manage.sh restart'; while (@ ob_end_flush()); // end all output buffers if any $proc = popen($cmd, 'r'); echo '<pre>'; while (!feof($proc)) { echo fread($proc, 4096); @ flush(); } echo '</pre>'; // // Converts Bashoutput to colored HTML // function convertBash($cmd) { $dictionary = array( '\e[1;30m' => '<span style="color:black">', '\e[1;31m' => '<span style="color:red">', '\e[1;32m' => '<span style="color:green">', '\e[1;33m' => '<span style="color:yellow">', '\e[1;34m' => '<span style="color:blue">', '\e[1;35m' => '<span style="color:purple">', '\e[1;36m' => '<span style="color:cyan">', '\e[1;37m' => '<span style="color:white">' ); $htmlString = str_replace(array_keys($dictionary), $dictionary, $cmd); return $htmlString; } ?>
  5. ok now i get it so i have to change this in bash script: WIT="\033[0;39m" ROOD="\033[1;31m" GROEN="\033[1;32m" but what about the part of code to use this function with the code above? Thank you for your help!
  6. I give up I need some working example 1st to get this understand better.
  7. I'm trying to make colourized output of bash script in php. So far I have this: <?php $cmd = '/home/thebalk/FiveM/manage.sh restart'; while (@ ob_end_flush()); // end all output buffers if any $proc = popen($cmd, 'r'); echo '<pre>'; while (!feof($proc)) { echo fread($proc, 4096); @ flush(); } echo '</pre>'; // // Converts Bashoutput to colored HTML // function convertBash($cmd) { $dictionary = array( '[1;30m' => '<span style="color:black">', '[1;31m' => '<span style="color:red">', '[1;32m' => '<span style="color:green">', '[1;33m' => '<span style="color:yellow">', '[1;34m' => '<span style="color:blue">', '[1;35m' => '<span style="color:purple">', '[1;36m' => '<span style="color:cyan">', '[1;37m' => '<span style="color:white">', '[m' => '</span>' ); $htmlString = str_replace(array_keys($dictionary), $dictionary, $cmd); return $htmlString; } ?> and my output looks like this: [1;36m BOT:[0;39m THE [1;32m TheBalkanRP-SRV01-test SERVER [0;39m WAS RUNNING [1;36m BOT:[0;39m STOPPING THE [1;32m TheBalkanRP-SRV01-test SERVER [1;36m BOT:[0;39m GTA V SERVER HAS STOPPED [1;36m BOT:[0;39m REMOVING CACHE FOLDER [1;36m BOT:[1;31m CACHE FOLDER HAS BEEN REMOVED [0;39m [1;36m BOT:[0;39m STARTING THE [1;32m TheBalkanRP-SRV01-test [0;39m SERVER [1;36m BOT:[1;32m SERVER HAS STARTED [0;39m I know my function is not connected with the code above but what is the right way to do it? Thank you!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.