LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Bash: Check if a screen exist (https://www.linuxquestions.org/questions/programming-9/bash-check-if-a-screen-exist-4175435648/)

fatalerror0x00 11-04-2012 09:19 PM

Bash: Check if a screen exist
 
Should I convert this large section of code to a version of my own:

Code:


is_running(){
        # Checks for the minecraft servers screen session
        # returns true if it exists.
        pidfile=${MCPATH}/${SCREEN}.pid

        if [ -r "$pidfile" ]
        then
                pid=$(cat $pidfile)
                if ps ax | grep -v grep | grep ${pid} | grep "${SCREEN}" > /dev/null
                then
                        return 0
                else
                        echo "Rogue pidfile found!"
                        return 1
                fi
        else
                if ps ax | grep -v grep | grep "${SCREEN} ${INVOCATION}" > /dev/null
                then
                        echo "No pidfile found, but server's running."
                        echo "Re-creating the pidfile."
                       
                        pid=$(ps ax | grep -v grep | grep "${SCREEN} ${INVOCATION}" | cut -f1 -d' ')
                        as_user "echo $pid > $pidfile"

                        return 0
                else
                        return 1
                fi
        fi
}

or should I use my own little variable with a my current variable for it /home/shawn/.screen/*.PhantasyCraft

obviously with the name of the variable infront of it and equals but you got it and then use an if statement with test and test it for existance and readable maybe? I feel maybe readable is all i should chcek for like the other script.

My goal here and for reliability. So could you tell me why or why I shouldn't use one or the other methods. Thanks :)

Habitual 11-05-2012 08:00 AM

screen, screen exists, arguments, and countdowns.

What are you doing exactly?

fatalerror0x00 11-05-2012 10:58 AM

lol well I am creating a screen which runs our minecraft server which is pretty well along i just need help with a few things and I'll be done with in by the end of the week :) I needed to know if a screen exist so I'm not running a acidently running another screen with the same name and not a different process id cause there is no reason I should have 2 with the same name EVER. So in these scripts specifically I want them to fail if any process id owns has that name for screen and then I will have to manually check it out

arguments for times to sleep i think thats all arguments have been used for so far but there will be more when I make this all one big script possibly if i decide to do that. I'm a little iffy on that but think it be great if I can pull it off :) and last countdowns well i needed a countdown for pretty much like I said in my post i need something to count down to 0 and along the way i will check for how many seconds are left. cause I wanna make the argument hold any time count from there and say whatever at certaiin set times. Thats what I'm doing :P and you guys have been great helping me guding me giving me examples for me to expand on :)


All times are GMT -5. The time now is 01:16 PM.