Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Problem ze skryptem exec i include
Forum PHP.pl > Forum > PHP
kefu
Witam przejdę od razu do rzeczy napisałem malutki skrypcik który z poziomu www odpala proces na shellu ale nie działa i nie mam pomysłów jak to zastosować

Kod
  1. <?php
  2. system('cd /home/ts3/teamspeak3-server_linux-x86/');
  3. shell_exec('ts3server_startscript.sh start');
  4. echo '<font color="green">Serwer TS3 Zostal uruchomiony</font>';
  5. ?>


Drugim problemem jest ze apache nie czyta mi include w php i nie wiem co zrobić próbowałem już wszystkiego serwer stoi na starym komputerze jest on przeznaczony pod shella.

Za pomoc z góry dziękuję smile.gif
Pozdrawiam Kefu.
Krzychu105
a dlaczego od razu nie zrobisz ?
Kod
shell_exec('/home/ts3/teamspeak3-server_linux-x86/ts3server_startscript.sh start');
kefu
Ponieważ to nic nie daje już próbowałem twojego rozwiązania wcześniej smile.gif
MrMag
zobacz ten temat http://forum.php.pl/index.php?showtopic=86587
kefu
Nic nie dało niestety... ponieważ nie rozumie funkcji start :/
MrMag
pokaz kod
sazian
rozumiem że jeśli wpiszesz w konsoli
Kod
/home/ts3/teamspeak3-server_linux-x86/ts3server_startscript.sh start

to wszystko działa questionmark.gif
jeśli tak to najmniejszej linij oporu możesz utworzyć nowy plik i w nim dać
Kod
#!/bin/bash
/home/ts3/teamspeak3-server_linux-x86/ts3server_startscript.sh start

lub dać to w jednym poleceniu
Kod
cd /home/ts3/teamspeak3-server_linux-x86/;./ts3server_startscript.sh start
kefu
Tak dobrze rozumiesz myślisz o stworzeniu pliku *.sh i odpaleniu go przez www? Jeżeli tak to nie jest dobry pomysł bo inni użytkownicy będą mieli do niego dostęp.
sazian
nie,
ja myślałem o stworzeniu pojedynczego pliku i w nim umieszczeniu tego polecenia, a plik byłby uruchamiany dalej z poziomu php
chociaż to może i głupi pomysł biggrin.gif

ale już mam inny winksmiley.jpg
zamiast shell_exec daj exec i zobacz jakiś błąd jest - oczywiście nie błąd php tylko w tym poleceniu
kefu
Nie ma żadnego błędu ale w PHP to nie trybie nie wiem dlaczego :/
A w include mam taki błąd

  1. Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /var/www/log.php:2) in /var/www/log.php on line 3
  2.  
  3. Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /var/www/log.php:2) in /var/www/log.php on line 3


w 3 lini jest


@refresh
Hekko
A co jest w linii 2 ? Najlepiej to pokaż cały kod.
ZuyPan
Z tego co wiem taki błąd z include pojawia się gdy do pliku np.
  1. <?php
  2. include ('bla.php');
  3. //reszta kodu


includujesz plik bla.php w którym również zaczynasz sesje czyli
  1. <?php
  2. //reszta kodu

kefu
z include naprawiłem błąd to było przez kodowanie winksmiley.jpg ale z tym shell_exec mam nadal problem ;/
MrMag
Cytat(kefu @ 2.01.2011, 17:20:21 ) *
Tak dobrze rozumiesz myślisz o stworzeniu pliku *.sh i odpaleniu go przez www? Jeżeli tak to nie jest dobry pomysł bo inni użytkownicy będą mieli do niego dostęp.


czemu nie chcesz wlasnie tak zrobic? Kto bedzie mial do tego dostep? Jacy uzytkownicy?
kefu
wszyscy którzy są na shellu przez 1 *.sh odpalam ale komendy wyskakują nic więcej serwer się nie uruchamia...
MrMag
pokaz wszystko: kod php i skrypty sh
kefu
Trochę tego jest :0

Skrypt który powinien uruchomić server
  1. <?php
  2. system("/bin/sh /home/ts/teamspeak3-server_linux-x86/ts3server_startscript.sh start");
  3. ?>


a tutaj plik ts3server_startscript.sh
  1. #!/bin/sh
  2. # Copyright (c) 2010 TeamSpeak Systems GmbH
  3. # All rights reserved
  4.  
  5. COMMANDLINE_PARAMETERS="${2}" #add any command line parameters you want to pass here
  6. BINARYPATH="$(dirname "${0}")"
  7. cd "${BINARYPATH}"
  8. LIBRARYPATH="$(pwd)"
  9.  
  10. if [ -e "ts3server_linux_x86" ]; then
  11. BINARYNAME="ts3server_linux_x86"
  12. elif [ -e "ts3server_linux_amd64" ]; then
  13. BINARYNAME="ts3server_linux_amd64"
  14. elif [ -e "ts3server_freebsd_x86" ]; then
  15. BINARYNAME="ts3server_freebsd_x86"
  16. elif [ -e "ts3server_freebsd_amd64" ]; then
  17. BINARYNAME="ts3server_freebsd_amd64"
  18. else
  19. echo "Could not locate binary file, aborting"
  20. exit 5
  21. fi
  22.  
  23. case "$1" in
  24. start)
  25. if [ -e ts3server.pid ]; then
  26. if ( kill -0 $(cat ts3server.pid) 2> /dev/null ); then
  27. echo "The server is already running, try restart or stop"
  28. exit 1
  29. else
  30. echo "ts3server.pid found, but no server running. Possibly your previously started server crashed"
  31. echo "Please view the logfile for details."
  32. rm ts3server.pid
  33. fi
  34. fi
  35. if [ "${UID}" = "0" ]; then
  36. echo WARNING ! For security reasons we advise: DO NOT RUN THE SERVER AS ROOT
  37. c=1
  38. while [ "$c" -le 10 ]; do
  39. echo -n "!"
  40. c=$((++c))
  41. done
  42. echo "!"
  43. fi
  44. echo "Starting the TeamSpeak 3 server"
  45. if [ -e "$BINARYNAME" ]; then
  46. if [ ! -x "$BINARYNAME" ]; then
  47. echo "${BINARYNAME} is not executable, trying to set it"
  48. chmod u+x "${BINARYNAME}"
  49. fi
  50. if [ -x "$BINARYNAME" ]; then
  51. export LD_LIBRARY_PATH="${LIBRARYPATH}:${LD_LIBRARY_PATH}"
  52. "./${BINARYNAME}" ${COMMANDLINE_PARAMETERS} > /dev/null &
  53. echo $! > ts3server.pid
  54. echo "TeamSpeak 3 server started, for details please view the log file"
  55. else
  56. echo "${BINARNAME} is not exectuable, cannot start TeamSpeak 3 server"
  57. fi
  58. else
  59. echo "Could not find binary, aborting"
  60. exit 5
  61. fi
  62. ;;
  63. stop)
  64. if [ -e ts3server.pid ]; then
  65. echo -n "Stopping the TeamSpeak 3 server"
  66. if ( kill -TERM $(cat ts3server.pid) 2> /dev/null ); then
  67. c=1
  68. while [ "$c" -le 300 ]; do
  69. if ( kill -0 $(cat ts3server.pid) 2> /dev/null ); then
  70. echo -n "."
  71. else
  72. break
  73. fi
  74. c=$((++c))
  75. done
  76. fi
  77. if ( kill -0 $(cat ts3server.pid) 2> /dev/null ); then
  78. echo "Server is not shutting down cleanly - killing"
  79. kill -KILL $(cat ts3server.pid)
  80. else
  81. echo "done"
  82. fi
  83. rm ts3server.pid
  84. else
  85. echo "No server runing (ts3server.pid is missing)"
  86. exit 7
  87. fi
  88. ;;
  89. restart)
  90. $0 stop && $0 start || exit 1
  91. ;;
  92. status)
  93. if [ -e ts3server.pid ]; then
  94. if ( kill -0 $(cat ts3server.pid) 2> /dev/null ); then
  95. echo "Server is running"
  96. else
  97. echo "Server seems to have died"
  98. fi
  99. else
  100. echo "No server running (ts3server.pid is missing)"
  101. fi
  102. ;;
  103. *)
  104. echo "Usage: ${0} {start|stop|restart|status}"
  105. exit 2
  106. esac
  107.  
  108.  


Dałem te 2 najważniejsze!
MrMag
bardzo nieuwaznie czytales ten temat smile.gif

zobacz

  1. shell_exec("./odpal_serwer > /dev/null");


Kod
#!/bin/sh
/home/ts/teamspeak3-server_linux-x86/ts3server_startscript.sh start &


zobacz czy w ogole skrypt php/sh ma uprawnienia do wywolania tej komendy. zobacz prawa dostepu do niego.
kefu
Nic nie dało nawet nie wyświetliło ze serwer się odpalił jak to robiło przy system.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.