Solved

What is the converted result of this Bash script to sh for Solaris 10?

Posted on 2013-12-04
13
553 Views
Last Modified: 2013-12-04
What is the converted result of this Bash script to #!/sbin/sh for Solaris 10?

 
set JAVA_HOME=/u00/app/jdk1.7.0_45
set AS_JAVA=/u00/app/jdk1.7.0_45
set JAVA_BINDIR="${JAVA_HOME}/bin"

echo "Set PATH with Java"
echo $PATH | /bin/grep -v "${JAVA_BINDIR}"
if ( $status == 0 ) then
     setenv PATH "${JAVA_BINDIR}:${PATH}"
endif

GLASSFISH=/u00/app/oracle/product/glassfish4
DERBY_BIN=/u00/app/oracle/product/glassfish4/javadb/bin

case "$1" in
‘start’)
  echo "Starting GlassFish from $GLASSFISH" > /tmp/GlassFishStarted.txt
  /bin/su glassfish "$GLASSFISH/bin/asadmin" start-database
  /bin/su glassfish "$GLASSFISH/bin/asadmin" start-domain appsand01
  ;;
stop)
  echo "Stopping GlassFish from $GLASSFISH"
  sudo -u glassfish -E "$GLASSFISH/bin/asadmin" stop-domain appsand01
  sudo -u glassfish -E "$GLASSFISH/bin/asadmin" stop-database
  ;;
restart)
  $0 stop
  $0 start
  ;;
status)
  echo "# GlassFish at $GLASSFISH:"
  sudo -u glassfish -E "$GLASSFISH/bin/asadmin" list-domains | grep -v Command
  sudo -u glassfish -E "$GLASSFISH/bin/asadmin" list-domains | grep -q "appsand01 running"
  if [ $? -eq 0 ]; then
    sudo -u glassfish -E "$GLASSFISH/bin/asadmin" uptime | grep -v Command
    echo "\n# Deployed applications:"
    sudo -u glassfish -E "$GLASSFISH/bin/asadmin" list-applications --long=true --resources | grep -v Command
    echo "\n# JDBC resources:"
    sudo -u glassfish -E "$GLASSFISH/bin/asadmin" list-jdbc-resources | grep "jdbc/"
  fi
  echo "\n# Derby:"
  sudo -u glassfish -E "$DERBY_BIN/NetworkServerControl" ping | sed "s/^.* : //"
  ;;
*)
  echo "Usage: $0 {start|stop|restart|status}"
  exit 1
  ;;
esac

Open in new window

0
Comment
Question by:bcarlis
  • 6
  • 6
13 Comments
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 500 total points
ID: 39696794
I'm confused. Didn't you initially write "converted to csh"??

This is for csh:

#!/bin/csh
echo "Set java shell variables"
set JAVA_HOME=/u00/app/jdk1.7.0_45
set AS_JAVA=/u00/app/jdk1.7.0_45
set JAVA_BINDIR="${JAVA_HOME}/bin"

echo "Set PATH with Java"
echo $PATH | /bin/grep -q -v "${JAVA_BINDIR}"
if ( $status == 0 ) then
     setenv PATH "${JAVA_BINDIR}:${PATH}"
endif

set GLASSFISH=/u00/app/oracle/product/glassfish4
set DERBY_BIN=/u00/app/oracle/product/glassfish4/javadb/bin

switch ( $1 )
case start:
  echo "Starting GlassFish from $GLASSFISH" > /tmp/GlassFishStarted.txt
  /bin/su glassfish "$GLASSFISH/bin/asadmin" start-database
  /bin/su glassfish "$GLASSFISH/bin/asadmin" start-domain appsand01
  breaksw
case stop:
  echo "Stopping GlassFish from $GLASSFISH"
  sudo -u glassfish -E "$GLASSFISH/bin/asadmin" stop-domain appsand01
  sudo -u glassfish -E "$GLASSFISH/bin/asadmin" stop-database
  breaksw
case restart:
  $0 stop
  $0 start
  breaksw
case status:
  echo "GlassFish at ${GLASSFISH}:"
  sudo -u glassfish -E "$GLASSFISH/bin/asadmin" list-domains | grep -v Command
  sudo -u glassfish -E "$GLASSFISH/bin/asadmin" list-domains | grep -q "appsand01 running"
  if ( $status == 0 ) then
   sudo -u glassfish -E "$GLASSFISH/bin/asadmin" uptime | grep -v Command
   echo
   echo "# Deployed applications:"
   sudo -u glassfish -E "$GLASSFISH/bin/asadmin" list-applications --long=true --resources | grep -v Command
   echo
   echo "# JDBC resources:"
   sudo -u glassfish -E "$GLASSFISH/bin/asadmin" list-jdbc-resources | grep "jdbc/"
  endif
  echo
  echo "# Derby:"
  sudo -u glassfish -E "$DERBY_BIN/NetworkServerControl" ping | sed "s/^.* : //"
  breaksw
default:
  echo "Usage: $0 {start|stop|restart|status}"
  exit 1
endsw

Open in new window

0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 500 total points
ID: 39696834
"sh" should need just a few modifications:

#!/sbin/sh
JAVA_HOME=/u00/app/jdk1.7.0_45
AS_JAVA=/u00/app/jdk1.7.0_45
JAVA_BINDIR="${JAVA_HOME}/bin"

echo "Set PATH with Java"
echo $PATH | /bin/grep -v "${JAVA_BINDIR}"
if [ $? -eq 0 ]; then
     PATH="${JAVA_BINDIR}:${PATH}"
     export PATH
fi

GLASSFISH=/u00/app/oracle/product/glassfish4
DERBY_BIN=/u00/app/oracle/product/glassfish4/javadb/bin

case $1 in
start)
  echo "Starting GlassFish from $GLASSFISH" > /tmp/GlassFishStarted.txt
  /bin/su glassfish "$GLASSFISH/bin/asadmin" start-database
  /bin/su glassfish "$GLASSFISH/bin/asadmin" start-domain appsand01
  ;;
stop)
  echo "Stopping GlassFish from $GLASSFISH"
  sudo -u glassfish -E "$GLASSFISH/bin/asadmin" stop-domain appsand01
  sudo -u glassfish -E "$GLASSFISH/bin/asadmin" stop-database
  ;;
restart)
  $0 stop
  $0 start
  ;;
status)
  echo "# GlassFish at $GLASSFISH:"
  sudo -u glassfish -E "$GLASSFISH/bin/asadmin" list-domains | grep -v Command
  sudo -u glassfish -E "$GLASSFISH/bin/asadmin" list-domains | grep -q "appsand01 running"
  if [ $? -eq 0 ]; then
    sudo -u glassfish -E "$GLASSFISH/bin/asadmin" uptime | grep -v Command
    echo "\n# Deployed applications:"
    sudo -u glassfish -E "$GLASSFISH/bin/asadmin" list-applications --long=true --resources | grep -v Command
    echo "\n# JDBC resources:"
    sudo -u glassfish -E "$GLASSFISH/bin/asadmin" list-jdbc-resources | grep "jdbc/"
  fi
  echo "\n# Derby:"
  sudo -u glassfish -E "$DERBY_BIN/NetworkServerControl" ping | sed "s/^.* : //"
  ;;
*)
  echo "Usage: $0 {start|stop|restart|status}"
  exit 1
  ;;
esac

Open in new window

0
 
LVL 2

Author Comment

by:bcarlis
ID: 39697050
Sorry, I looked at the other scripts in the init.d dir and say the #!/sbin/sh

this is what I am getting from the output
/etc/init.d/glassfish status
Set PATH with Java
/usr/sfw/bin:/usr/sfw/sbin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/ucb:/etc:/usr/openwin/bin:/usr/local/samba/bin:/usr/ccs/bin:/usr/local/bin:.
# GlassFish at /u00/app/oracle/product/glassfish4:
/etc/init.d/glassfish: sudo: not found
/etc/init.d/glassfish: sudo: not found
grep: illegal option -- q
Usage: grep -hblcnsviw pattern file . . .

# Derby:
/etc/init.d/glassfish: sudo: not found

Open in new window

0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 2

Author Comment

by:bcarlis
ID: 39697053
could you edit the answers and remove my headed information - name, company etc
thank you..
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 39697065
Scripts in /etc/init.d are usually run by root. So you don't have to use sudo, a simple "su" should suffice, e.g.:

su - glassfish -c "$GLASSFISH/bin/asadmin list-domains | /usr/xpg4/bin/grep -q -v Command"

Open in new window

In your above lines 17 and 18 you're already using "su". Please note that you must use "su -" to get the target user's environment and that you must prefix the command to be executed with "-c" and surround the command itself with double quotes, so the mentioned line 17 should read:

/bin/su - glassfish -c "$GLASSFISH/bin/asadmin start-database"

To make the "quiet" switch ("-q") of "grep" work under Solaris you must use
"/usr/xpg4/bin/grep" as shown in the example above.
0
 
LVL 2

Author Comment

by:bcarlis
ID: 39697200
Great it compiles... but something is not working

Can't I just su - glassfsh once somehow ?

status)
  echo '# GlassFish at "$GLASSFISH:"'
  /bin/su - glassfsh -c "$GLASSFISH/bin/asadmin" list-domains | grep -v Command
  /bin/su - glassfsh -c "$GLASSFISH/bin/asadmin" list-domains | /usr/xpg4/bin/grep -q "appsand01 running"
  if [ $? -eq 0 ]; then
    /bin/su - glassfsh -c "$GLASSFISH/bin/asadmin" uptime | grep -v Command
    echo '\n# Deployed applications:'
    /bin/su - glassfsh -c "$GLASSFISH/bin/asadmin" list-applications --long=true --resources | /usr/xpg4/bin/grep -v Command
    echo '\n# JDBC resources:'
    /bin/su - glassfsh -c "$GLASSFISH/bin/asadmin" list-jdbc-resources | grep "jdbc/"
  fi
  echo '\n# Derby:'
  /bin/su - glassfsh -c "$DERBY_BIN/NetworkServerControl" ping | sed "s/^.* : //"
  ;;
*)
  echo 'Usage: $0 {start|stop|restart|status}'
  exit 1
  ;;

Open in new window


OUTPUT from above:
# GlassFish at /u00/app/oracle/product/glassfish4
Oracle Corporation      SunOS 5.10      Generic Patch   January 2005
Set path shell variable
Set PATH with Java
/usr/bin:
Set GlassFish Environment
/u00/app/jdk1.7.0_45/bin:/usr/bin:
Set Environment
Shortcut aliases
Use "exit" to exit and "help" for online help.

Open in new window


All this is from one su - glassfsh
Oracle Corporation      SunOS 5.10      Generic Patch   January 2005
Set path shell variable
Set PATH with Java
/usr/bin:
Set GlassFish Environment
/u00/app/jdk1.7.0_45/bin:/usr/bin:
Set Environment
Shortcut aliases

Open in new window

0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 500 total points
ID: 39697211
Yes, that's what glassfish's profile writes to the terminal.

The question is, do you need anything set by that profile, particularly any "glassfish" specific environment variables?

If you don't, you can use just "su" without the following dash.

If something is needed from the profile - could you set this in the script itself to avoid having to run "su -"?

And you can't "su -" just once, because "su -" without a following command starts its own shell and thus requires a manually typed "exit" to return to the calling script.
0
 
LVL 2

Author Comment

by:bcarlis
ID: 39697215
What is happening is
  /bin/su - glassfsh -c "$GLASSFISH/bin/asadmin" list-domains | grep -v Command

it is getting hung on  if [ $? -eq 0 ]; then ??




Actually how whould I write:

status)
  echo '# GlassFish at "$GLASSFISH:"'
  /bin/su - glassfsh -c "$GLASSFISH/bin/asadmin" 

< list-domains | grep -v Command
< list-domains | /usr/xpg4/bin/grep -q "appsand01 running"
  
if [ $? -eq 0 ]; then
    < uptime | grep -v Command
    echo '\n# Deployed applications:'
    < list-applications --long=true --resources | /usr/xpg4/bin/grep -v Command
    echo '\n# JDBC resources:'
    < list-jdbc-resources | grep "jdbc/"
  fi
  echo '\n# Derby:'
  /bin/su - glassfsh -c "$DERBY_BIN/NetworkServerControl" ping | sed "s/^.* : //"
  ;;
*)
  echo 'Usage: $0 {start|stop|restart|status}'
  exit 1
  ;;

Open in new window


Where asadmin is a command prompt and just want to pipe the commands into the existing prompt? :)

This
/bin/su - glassfsh -c "$GLASSFISH/bin/asadmin"
gives this
asadmin>
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 500 total points
ID: 39697218
You can't pipe commands into a prompt, only into a command/program which reads stdin.
0
 
LVL 2

Author Comment

by:bcarlis
ID: 39697221
Thank you..

/bin/su - glassfsh -c "$GLASSFISH/bin/asadmin" list-domains | grep -v Command

I placed list-domains | grep -v Command in the quotes to make all one command

/bin/su - glassfsh -c "$GLASSFISH/bin/asadmin list-domains | grep -v Command"

otherwise it was stopping at
Oracle Corporation      SunOS 5.10      Generic Patch   January 2005
Set path shell variable
Set PATH with Java
/usr/bin:
Set GlassFish Environment
/u00/app/jdk1.7.0_45/bin:/usr/bin:
Set Environment
Shortcut aliases
Use "exit" to exit and "help" for online help.
asadmin>
0
 
LVL 2

Author Comment

by:bcarlis
ID: 39697223
Thank you very much for your help, I will tweak it tomorrow.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39697224
>> I placed list-domains | grep -v Command in the quotes to make all one command <<

That's indeed what I suggested - see ID: 39697065 above!
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
unix solaris snoop command 6 99
AWS CLI issues with Tags 3 77
AWS CLI - Instances, Volumes & Tagging 2 94
remove one line from a file in solaris 8 29
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question