LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-04-2012, 09:19 PM   #1
fatalerror0x00
Member
 
Registered: Oct 2012
Location: Holden, ME, USA
Distribution: SlackWare64 14.00
Posts: 185

Rep: Reputation: 0
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
 
Old 11-05-2012, 08:00 AM   #2
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
screen, screen exists, arguments, and countdowns.

What are you doing exactly?

Last edited by Habitual; 11-05-2012 at 08:01 AM.
 
Old 11-05-2012, 10:58 AM   #3
fatalerror0x00
Member
 
Registered: Oct 2012
Location: Holden, ME, USA
Distribution: SlackWare64 14.00
Posts: 185

Original Poster
Rep: Reputation: 0
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Check if directory DOES NOT exist in BASH Drigo Linux - Newbie 12 05-03-2012 06:35 AM
Check whether a .zip exist or not xombboxer Linux - Newbie 3 04-08-2012 12:17 PM
how to check directory exist or not nagendrar Solaris / OpenSolaris 1 04-30-2010 02:06 AM
check if directory exist jaepi Programming 6 05-10-2007 08:45 PM
Check if email exist or not proNick Linux - Software 2 08-27-2005 01:25 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration