Sponsored Content
Top Forums Shell Programming and Scripting Shell Script for Java version switch Post 302828875 by bigbenn on Wednesday 3rd of July 2013 11:10:47 AM
Old 07-03-2013
Shell Script for Java version switch

Hello all I am writing a shell script for unix, and I am trying to get it to ask me if instances are stopped, and then if the version of java running is correct, if not I want it to ask me to switch to the other bit version. I am newish to shell and not clear on how to to input prompts for yes/no etc, I cant get it to run properly,could someone please help?

Code:
SCRIPT=$(basename "$0")
VERSION='$Revision: 6327 $'
VERBOSE=0
NUMBITS=0
YES=0
# , support version specification
function usage {
  cat << EOM
usage: $SCRIPT [-h] [-v] [-V] [-b] [-y]
  where:
    -b bits java bit level 32 or 64
    -h show this message and exit
    -v add verbosity
    -V show version and exit
    -y answer prompts with yes
EOM
        exit 1
}
while getopts ":b:hvVy" opt
do
  case "$opt" in
    b ) NUMBITS=$OPTARG ;;
    h )
      usage
      ;;
    v ) ((VERBOSE+=1)) ;;
 V )    
      echo "$SCRIPT VERSION: $(echo $VERSION | awk '{ print $2 }')"
      exit 0
      ;;
    y ) YES=1 ;;
    * )
      echo "Unexpected option \"$opt\""
      usage
      ;;
  esac
done
shift $(($OPTIND - 1))
# Dependencies:
for DEPENDENCIES in symlink-resolve
do
  if ( which $DEPENDENCIES 2>&1 | grep -e "^which: no " -e "^no ")
  then
    echo "Aborting - unable to resolve dependency: $DEPENDENCIES"
    exit 1
  fi
done
unset DEPENDENCIES
case "$NUMBITS" in
  32|64)
  ;;
  *)
    echo "Invalid bits specified: $NUMBITS"
    usage
  ;;
esac
SHARE=/app/share/java/bin
JAVASHARE=${SHARE}/java
if [ -L "$JAVASHARE" ]
then
# if YES is 0, prompt user asking if instances are stopped
#              if answer is no exit
read -y " Did you stop all instances before this? [y/n] answer
if [ $answer != [-y] ]
then
echo "Cannot proceed becuases instances not stopped" exit
else
echo "Current Java Version running on machine is: $(java -version)
fi
# Is current version what we want?
# If yes say so and exit
read -y "Is this version of Java the current version you want? [y/n]" answer
if [ $answer =! [-y] ]
then exit
else
read -b "Please choose which bit version you want Java at? [32/64]" NUMBITS
if [ $NUMBITS =! [-b] ]
then setServerJava -b $NUMBITS
fi
fi
JAVACUR=$(symlink-resolve $JAVASHARE)
# test and make sure it is directory
# extract the bits from the current
#OLDBITS
  JAVAP=$(basename $JAVACUR)
  JAVAN=$(echo "$JAVAP" | sed -e "s/$OLDBITS/$NUMBITS/")
  JAVANEW=${SHARE}/${JAVANEW}
  # test is dir JAVANEW error exit if not
  cd $SHARE
  rm $JAVASHARE
  ln -s $JAVANEW $JAVASHARE
  # darn I am good

else
  echo "Symlink not found: $JAVASHARE"
fi

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Switch from one database to other using shell script

Hi all, This is my first ever post to any forum so, dont let this go in vain...........:) Here is the scenario........ I have logged into the unix where oracle_sid is initialized for some X database in the .profile. I have a unix script where some sql query which fetches data from X... (3 Replies)
Discussion started by: sachinkl
3 Replies

2. Shell Programming and Scripting

Switch User in within a Shell Script

Hi Experts, I'm trying to write a shell script to stop few things where i have to use another user to execute a command. Otherwise it will not work. Your help is really appreciated Thanks, (16 Replies)
Discussion started by: Afi_Linux
16 Replies

3. UNIX for Advanced & Expert Users

Advanced Search * View * Edit JAVA version to WORK in GLASSFISH Forum topic JAVA version

Would like to confirm the ff. I got confused actually with the version I needed to download that will work on glassfish 3.0.1 a. Debian Squeeze (HP DL360). Need to use java version6 On Debian, I did apt-get install sun-java6-jdk. So when I check it's java version "1.6.0_22" Java(TM) SE... (1 Reply)
Discussion started by: lhareigh890
1 Replies

4. Shell Programming and Scripting

Switch user inside shell script

Hi, I am trying to create one script where I have to login as another user inside the script to exeute some commands How can i achieve this? Many thanks in advance. (4 Replies)
Discussion started by: prarat
4 Replies

5. Shell Programming and Scripting

How to switch user using shell script ?

Hi, script1.sh script2.sh script3.sh From above, script1.sh is the main script which is executed from root user, creates installation directory, changing ownership and execution rights etc..etc.. and finally calls scripot2.sh and script3.sh to create the database as well as for post... (1 Reply)
Discussion started by: milink
1 Replies

6. UNIX for Advanced & Expert Users

Help with server switch shell script

I need a script to change server automatically after performing some operations. The command for changing server is ssh username@servername . Then a prompt comes to enter a password. Then i need to perform some opertaions on the other server. How can i do this in a script? (1 Reply)
Discussion started by: pratikm23
1 Replies

7. UNIX for Dummies Questions & Answers

How to switch to a certain version of glibc?

Hello, I currently have glibc 2.13. I was wondering if you could teach me how to switch to : glibc2.3.2 I would really appreciate it if you tell me how to do it step by step since I am a beginner . thanks. (1 Reply)
Discussion started by: alireza6485
1 Replies

8. UNIX for Dummies Questions & Answers

How to switch the user before executing a shell script from web page??

hi, i want to execute a shell script as a different user. the flow is like this. there is a html web page from which i have to call a shell script. web server is apache. to call the shell script from html page, a perl script is required. so the html page calls the perl script and the perl... (2 Replies)
Discussion started by: Little
2 Replies

9. UNIX for Beginners Questions & Answers

How to switch user in shell script?

HI in a server we can't login with root user directly but i can login with different user and then i can switch to root user by su command Requirement is there anyway where i can write a script without mentioning password in file as mentioning the root password is not the... (3 Replies)
Discussion started by: scriptor
3 Replies
jconsole(1)						      General Commands Manual						       jconsole(1)

NAME
jconsole - J2SE Monitoring and Management Console SYNOPSIS
jconsole [ options ] [ pid | [ host:port ... ] ] PARAMETERS
pid Process ID of a Java VM that was started with -Dcom.sun.management.jmxremote option on the same machine. See JMX Monitoring and Management for details at http://java.sun.com/j2se/1.5.0/docs/guide/management/agent.html. host:port Host name on which the Java VM is running and the port number through which the Java VM's JMX Connector is published. See JMX Monitoring and Management for details at http://java.sun.com/j2se/1.5.0/docs/guide/management/agent.html. DESCRIPTION
The jconsole command launches a graphical console tool that enables you to monitor and manage Java applications and virtual machines on a local or remote machine. NOTE- This tool is experimental and may not be available in future versions of the JDK. OPTIONS
-interval=n Set the update interval to n seconds (default is 4 seconds) -notile Do not tile windows initially (for two or more connections) -version Output version information abd exit. -help Output help message and exit. SEE ALSO
Monitoring and Management for Java Platform at http://java.sun.com/j2se/1.5.0/docs/guide/management/index.html 06 Feb 2004 jconsole(1)
All times are GMT -4. The time now is 07:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy