LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-25-2010, 07:42 AM   #1
thomas2004ch
Member
 
Registered: Aug 2009
Posts: 539

Rep: Reputation: 33
A question about "if then fi" in script


Hi,

A script looks as follow:
Code:
#!/bin/sh

# Define the Jboss User:
JBOSSUSER=msgbp

# Define the Context:
CONTEXT=msgbp

# Define the MSGBP_HOME:
MSGBP_HOME="/opt/jboss/MSGBP"

# Read in option:
case "$1" in

start)
        nohup $MSGBP_HOME/bin/run.sh -c msgbp -b 130.144.164.232 &
        ;;


cleanup)
        if [ -n "'ps -fu $JBOSSUSER | grep -v grep | grep -v Agent | grep java | grep $CONTEXT'" ]
        then
                echo "JBoss is still running - please stop the service first"
        else
		echo "clean-up ..."
        fi
        ;;
*)
        echo "Usage: jboss { start | cleanup}"
        ;;
esac

# now we are at the end of all actions
exit 0
When I type
Code:
jboss cleanup
It should check if a Jboss instance is running.

My problem is: there is no Jboss instance running but it gives always out that "JBoss is still running - please stop the service first".

Besides, I've checked with ps -fu $JBOSSUSER | grep -v grep | grep -v Agent | grep java | grep $CONTEXT and the output string is empty.

Is there any error in my script?

Last edited by thomas2004ch; 05-25-2010 at 07:53 AM.
 
Old 05-25-2010, 07:56 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Yes. Change single quotes with back ticks to perform command substitution:
Code:
if [ -n "`ps -fu $JBOSSUSER | grep -v grep | grep -v Agent | grep java | grep $CONTEXT`" ]
 
Old 05-25-2010, 08:39 AM   #3
thomas2004ch
Member
 
Registered: Aug 2009
Posts: 539

Original Poster
Rep: Reputation: 33
Quote:
Originally Posted by colucix View Post
Yes. Change single quotes with back ticks to perform command substitution:
Code:
if [ -n "`ps -fu $JBOSSUSER | grep -v grep | grep -v Agent | grep java | grep $CONTEXT`" ]
My god, that's the reason.

Many thanks!
 
  


Reply



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
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 01:03 AM
Shell script: I have string "abc____def____ghi", how to make "abc def ghi" vouser Programming 8 03-09-2010 10:01 PM
automount 5.0.3 with auto.smb script yields "key "<name>" not found in map" rbergen Linux - Software 0 01-01-2010 12:27 PM
newbie question: whats the difference between "su root", "su" and "su -&quo mojarron Slackware 9 12-07-2009 04:08 PM
Can't install "glibmm" library. "configure" script can't find "sigc++-2.0&q kornerr Linux - General 4 05-10-2005 02:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:47 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