How to stop specific map by crontab

Results 1 to 8 of 8
  1. #1
    Apprentice LawOutLaw is offline
    MemberRank
    Sep 2011 Join Date
    14Posts

    How to stop specific map by crontab

    Hello everyone.

    I am sorry if such question has been posted here earlier, but i couldn't find any similar.

    So, as we know not all maps are useful during whole week. One of such maps for example is is12 (Forest Ruins). And I need to start it at 15:00 of Sunday and stop it at 18:00 without pwAdmin but using cron.

    I created bash script for starting

    startIS12.sh:
    Code:
    #!/bin/sh
    
    PW_PATH=/PWServer
    
    cd $PW_PATH/gamed; ./gs is12 >$PW_PATH/logs/game_all.log &
    Then wrote in crontab this

    crontab:
    Code:
    00 15 * * 0  root    /etc/cron.pw/startIS12.sh
    00 18 * * 0  root    /etc/cron.pw/stopIS12.sh
    And here I need in bash script for stop this map at 18:00 Sun as in crontab

    Something like this

    stopIS12.sh:
    Code:
    #!/bin/sh
    
    ps a | grep is12
    
    Get the id number from that list// how to get this ID by script?
    
    kill -9 idnumber //and how to insert found ID here?
    Please help with stop[map].sh script
    Last edited by LawOutLaw; 02-12-11 at 07:20 PM.


  2. #2
    Black Magic Development das7002 is offline
    MemberRank
    Apr 2010 Join Date
    EarthLocation
    2,188Posts

    Re: How to stop specific map by crontab

    heh, I needed something just like this a few days ago because Java is an asshole to start in init


    Code:
    kill -9 $(ps aux | grep "java -jar JTS3ServerMod.jar" | grep -v grep | cut -c10-15)
    replace the INSIDE of the quotation marks with command used to start process

    But that is only if you have absolutely no way of knowing what the process ID is when you start it

    You can modify the start script to do this

    Code:
    #!/bin/sh
    
    PW_PATH=/PWServer
    PID_PATH=$PW_PATH/pids
    #                            >> means append, > means overwrite
    cd $PW_PATH/gamed; ./gs is12 >> $PW_PATH/logs/game_all.log &
    #    $! contains the process ID of the last command run by user using it
    echo $! > $PID_PATH/is12.pid
    And for the kill script you could then use that pid file to do this

    Code:
    #!/bin/sh
    PID_PATH=/PWServer/pids
    
    kill -9 $(cat is12.pid)
    btw using $() is basically an anonymous function in bash, whatever comes out of the stdout in the end is the return value.
    Last edited by das7002; 02-12-11 at 08:13 PM.

  3. #3
    Apprentice LawOutLaw is offline
    MemberRank
    Sep 2011 Join Date
    14Posts

    Re: How to stop specific map by crontab

    Thanks a lot. I'll try it now :)

  4. #4
    Black Magic Development das7002 is offline
    MemberRank
    Apr 2010 Join Date
    EarthLocation
    2,188Posts

    Re: How to stop specific map by crontab

    Quote Originally Posted by LawOutLaw View Post
    Like this?
    Code:
    kill -9 $(ps aux | grep "./gs is12" | grep -v grep | cut -c10-15)
    Yes that would work, but see above as I edited post with a better method...

  5. #5
    Apprentice LawOutLaw is offline
    MemberRank
    Sep 2011 Join Date
    14Posts

    Re: How to stop specific map by crontab

    Quote Originally Posted by das7002 View Post
    Yes that would work, but see above as I edited post with a better method...
    Just first method is more useful for me in my opinion. Coz um using pwAdmin for start server and run all maps. And I don't know how to edit .jsp files containing commands which start and stop maps manually through pwAdmin. In such cases when I started specific map by pwAdmin I'll not be able to control which ID by creating pid files

  6. #6
    Nerd-IO Romulan is offline
    MemberRank
    Feb 2009 Join Date
    BelgiumLocation
    3,333Posts

    Re: How to stop specific map by crontab

    This is my method:
    Code:
    #!/bin/sh
    /bin/kill -9 `ps -ef | grep is12 | grep -v grep | awk '{print $2}'`
    And it works perfectly... I never got any issues since few months now.

  7. #7
    Angelemu founder tbnanubis is offline
    MemberRank
    Mar 2011 Join Date
    Unicorn ForestLocation
    527Posts

    Re: How to stop specific map by crontab

    Code:
    kill -9 `ps -x | grep is12 | grep -v grep | awk '{print $1}'`
    edit: ah damn thats the same romulan's version does, except with -x its the first column to select

    side note: awk, as well as gawk and sed are nice little command line tools that can do awsome stuff (awk is a small but turing-complete programming language).. get used to it and they are very helpful ;)

  8. #8
    Apprentice lewellyn is offline
    MemberRank
    Jul 2011 Join Date
    16Posts

    Re: How to stop specific map by crontab

    And don't forget pkill(1)...

    Just be careful with it, since it's fairly indiscriminate. 'pkill a' will kill EVERYTHING running (that the current UID can kill, of course) with the letter "a" in its process name.

    Code:
    man pkill



Advertisement