how do i script this (a challenge indeed)
ok first im a newb but this is not a newb question but please please explain anything fully please
i have been creating a counter strike source server on a linux box and with the help of the amazing people here i have managed to make it do the following upon execution of its script it ; 1) ftps into my main pc and update any maps waypoints or sound files from my main pc to my server 2) scans all maps and creates a maplist for the ones with bot support 3) updates my website with the current maplist 4) saves a text file with the maps that need bot support added for my reference 5) loads up the seven day stat award calculation 6) Loads into a screen hlstats 7) loads the server into a screen using a random map from a predifend list of good ones again NONE of that would of been possible with out the good people here and im hoping you guys can help a little further Ok there are certain maps that seem to freeze up the server, if this happen going into the terminal on the server pc and typing "screen -x css-server" then typing "changelevel" fixes the problem till it happens again but that only helps if im at home and spot it theres two ways i can think off to fix this neither i can figure out how to do right 1) make a cron job that does the above commands every 4 hours (no idea how exactly to implement that and it would cause a map change to be forced when not needed or cause up to 3 and half hour server downtime if the next map crashes) not ideal 2)create a button on my website (thats hosted on the same box) that executes a script said script could either do 2a) kill the hlstats(named stats) process and css-server (named css-server) process (though the process id always change the screens are named) then execute my start-up script for the server (named abc.sh in my home folder) this idea i like the most as it would refresh the default map to 2b)goes into screen -x css-server and types changelevel followed by return is what im asking even possible? im guesing 1 is but 2 would be so much nicer specialy 2a thank you in advance dave |
2a) kill the hlstats(named stats) process and css-server (named css-server) process (though the process id always change the screens are named) then execute my start-up script for the server (named abc.sh in my home folder) this idea i like the most as it would refresh the default map to
In it's most crude form something like: Code:
#!/bin/sh Code:
#!/bin/sh Of course it would be more interesting to find out if we could test the server for a response to automate it and find out why certain maps hang the server and blacklist them if they cause too much trouble. |
btw, if you want to run the script from a web interface, don't forget to run it using sudo and as the user running your cs-processes (or root, unsecure!!!), otherwise the process can't be killed.
|
ok not sure have explained it right best bet i guess if i post the scripts used so far
abc.sh the start script Code:
#!/bin/sh Code:
#!/bin/sh Code:
#!/bin/sh Code:
#!/bin/sh the scripts are in my home folder (i`ve left the update ftp script out as its not really relevent) is it possible to kill the screens without knowing the id or reserving a process id for each screen the other problem is i dont know how to run a script from a webpage so kinda need help with that too, "how i want to do it is to have a button on my webpage (which already is secure only friends can get to the page)just click it and the script runs i know i may be asking much of linux and much of you guys just hope you can help |
now that creas the two screens so unfortuly no binery locations to aim at
"pgrep -lf hlstats-awards" should do I think. is it possible to kill the screens without knowing the id or reserving a process id for each screen "screen -list" will list running sessions. |
as i say im a newb i really need step by step instructions lol sorry to be a pain
|
am i asking the imposible ?
or is i something that just cant be explained easierly? |
Here's a fairly easy way to do it: save the following to /somewhere/restart.php
Code:
<? system("/path/to/script/which/restarts/counterstrike"); ?> If you need to run it suid, it can't be a bash script. It, however, can be a perl script which runs a bash script. |
NACK, it can be a script if you use sudo instead of setting the suid bit.
and if you replace restart.php by <?php echo $PHP_SELF ?>, you can rename the file without loosing the link... |
ok so if i understand this correctly since the script needs to be run as usser mrgreaper not su
i create a page on my website called restart.php with the contents of Code:
? system("./restart.sh"); ?> Code:
kill x screen -list gives a list of them and shows there ids but there ids constantly change which causes no end of grief i guess i could have the script as Code:
screen -x css-server |
To give a screen session a particular name,
Code:
$ screen -S session-name Code:
$ screen -S session-name -X quit Also, to run a bash script as a particular user, you need to wrap it inside something, because bash doesn't like suid. Here's a perl script to wrap it in: Code:
#!/usr/bin/perl Or, as has been suggested, use sudo. Can't really help you with that, since I don't have experience with it. |
Quote:
to make the script executable, you must set the X bit in the file permissions, this can be done with "chmod 755 restart.sh" (allow owner to read, write and execute, all others may only read and execute it.) simply edit your sudo file (as root) with the command visudo and create an entry to allow the user running apache (or everyone if you like) to call your script and not having to specify its password ("NOPASSWORD" statement) (see man sudo for the syntax of the sudo file). Then execute "sudo restart.sh" with the php system command. if you don't use sudo, keep in mind that apache normally is running as nobody or wwwrun user or something like that, not as your user or even root! |
ok i cant understand above sorry perhaps im not bright enough, i tried to try it and hoped any error messages would help me to fix it but i got this when i go to restart.php
Code:
Warning: Unknown(/srv/www/htdocs/restart.php): failed to open stream: Permission denied in Unknown on line 0 /srv/www/htdocs/restart.php Code:
? system("./restart.sh"); ?> Code:
#!/usr/bin/perl Code:
$ screen -S css-server -X quit logged in as mrgreaper i chmod 755 the last restart.sh and attempted to run it from the console type programme built into linux it says ./restart.sh: line1: $: command not found ./restart.sh: line2: $: command not found if i do screen -x it lists 31864 stats (detached) 31868 css-server (detached) |
first problem: use <?php ...?> instead of <? ... ?> (some configs don't like the abbrev. php start tag)
$ problem: the dollar sign was only there to represent a shell prompt, like your "mrgreaper@yourmachine:~#" command prompt. So simply delete "$ " from these lines... your turn again ;) |
Quote:
deleted the $ symbols it closed one screen left the second open and said please specify command is it trying to close them too fast ? is it possible to inserert a 5 second pause between the commands ? your help is greatly greatly appreciated |
Quote:
about your screen problem i can't help you, as i don't use screen, someone else? |
Quote:
|
sorry, I'm out...
|
Firstly, this code says something to the effect of "specify command":
Code:
screen -S css-server -X quit You're probably not doing anything too fast, since screen (I would guess) doesn't exit until it has delivered its command. You can insert a five second delay (insert a line saying "sleep 5"), but I don't think you need to. Secondly, there's a convention of calling perl scripts (the one beginning with #!/usr/bin/perl) name.pl, not name.sh. Just a nitpicking, really. For the apache error, please post the output of Code:
$ ls -l /srv/www/htdocs/restart.php /srv/www/htdocs/restart.sh /home/mrgraper/restart.sh |
mrgreaper@linux:~> ls -l /srv/www/htdocs/restart.php /srv/www/htdocs/restart.sh /home/mrgreaper/restart.sh
-rwxr-xr-x 1 mrgreaper users 178 2006-09-14 14:13 /home/mrgreaper/restart.sh -rwx------ 1 mrgreaper users 98 2006-09-12 11:46 /srv/www/htdocs/restart.php -rwxr-xr-x 1 mrgreaper users 76 2006-09-11 17:28 /srv/www/htdocs/restart.sh and yes that is the root folder of apache /srv/www/htdoc once its working the restart php page will be made more secure just want to get it working at mo the lack of the quit command was indeed where i had gone wrong ... i di then have an error where it wasn`t loading the css-server screen when it ran the ./abc.sh i inserted 5 second pause between each command (not the echo command though) and it works wonderful now the php is the last remaining problemany ideas and doc nice thank you for your help and of course jonaskoelker |
Unless apache runs as mrgreaper (in which case why do you need to suid or sudo?), you need to chmod og+rx restart.php.
|
ok we apear to be getting closer
i did exactly as stated (while logged in as mrgreaper) now instead of bing an error page the page very quickly displays all the echo commands from my scripts but doesnt do the commands (and that includes the sleep commands) and all the echos are in one long line IE css off stats off folder change now running server scanning for new maps done starting stat server up stats up and running starting cstrike server all loaded you should see two screens with there ids You have now restarted the server. at least we know its loading all the scripts and going through it but i don`t understand why its not running the commands? could it be trying to run them on the pc the webpage is displayed on rather then the local pc? edit vnc`ed into the server pc loaded the page on its web browser same thing happened so now i really have no clue!? |
try:
Code:
<html> Also, try prepending "#!/bin/bash -x" to the shell script. There's a really long line in one of the code parts. Please wrap it around--it causes the page to become really huge and bulky, and cause horizontal scrolling. |
All times are GMT -5. The time now is 06:15 PM. |