Link to home
Start Free TrialLog in
Avatar of BILL Carlisle
BILL CarlisleFlag for United States of America

asked on

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

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

SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BILL Carlisle

ASKER

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

could you edit the answers and remove my headed information - name, company etc
thank you..
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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>
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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>
Thank you very much for your help, I will tweak it tomorrow.
>> 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!