Error running a .sh script when extracted from a jar file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error running a .sh script when extracted from a jar file.
# 8  
Old 01-05-2010
Quote:
Originally Posted by rdcwayx
could you please give me the output with below command?

Code:
sh -x ./install.sh


Running the above command gives the following output:
Code:
[oracle@vmhealthedb02]$ sh -x ./install.sh
+ $'\r'
: command not found2:
++ echo ./install.sh
++ awk -F install.sh '{print $1}'
+ packgeDir=$'./\r'
+ currDir=$'/home/oracle/hin-chd-capability-install-scripts-1.1.0-SNAPSHOT\r'
+ $'\r'
: command not found6:
+ cd $'./\r\r'
: No such file or directory/
+ $'\r'
: command not found8:
'/install.sh: line 23: syntax error near unexpected token `do
'/install.sh: line 23: `  do


---------- Post updated at 03:53 PM ---------- Previous update was at 03:50 PM ----------

Quote:
Originally Posted by dnbert
This is gonna sound silly, but I'm not sure what you're running. You do have /bin/sh right?

Yes, I do have the shell. The current shell that I am running under is ksh.


[oracle@vmhealthedb02]$ echo $SHELL
/bin/ksh

Last edited by Scott; 01-06-2010 at 01:55 PM.. Reason: Added code tags
# 9  
Old 01-05-2010
Not really understand your script, especially this line:

Code:
awk -F install.sh '{print $1}'

can you paste your code here?

Code:
cat install.sh

# 10  
Old 01-06-2010
Here is the install.sh script:
Code:
#/bin/bash

# determine the directory containing this script
packgeDir=`echo $0 | awk -F 'install.sh' '{print $1}'`
currDir=$PWD

cd "$packgeDir"

if [ -d schema ]
then

  printf "*** creating schema install script ***\n\n"

  script=schema/install.sql
  rm -fr $script

  printf "/* install script generated on " >> $script
  now=`date`
  printf "$now" >> $script
  printf " by my tiny script */\n\n" >> $script
  printf "whenever sqlerror exit failure\n" >> $script
  for file in `ls -1 schema/*.[Dd][Dd][Ll] | sort -g`
  do
    printf "prompt installing $file\n" >> $script
    printf "@" >> $script
    printf "$file\n" >> $script
    printf "prompt installed $file\n" >> $script
  done
  printf "exit success\n" >> $script

  printf "\ncommit;" >> $script
  printf "\nexit;\n" >> $script

  printf "*** done with schema install script ***\n\n"

fi
################################################################################

if [ -d ref-data ]
then

  printf "*** creating ref data install script ***\n\n"

  cd ref-data
  script=install.sh
  rm -fr $script

  printf "#!/bin/bash\n\n" >> $script
  printf "cd ref-data\n\n" >> $script
  for file in `ls -1 *.[Dd][Mm][Pp] | sort -g`
  do
    printf "cp -f $file \$DATA_PUMP_DIR\n" >> $script
    printf "rm -f \$DATA_PUMP_DIR/${file}.log\n" >> $script
    printf "impdp 'userid=\"/ as sysdba\"' logfile=${file}.log " >> $script
    printf "directory=DATA_PUMP_DIR dumpfile=$file " >> $script
    printf "table_exists_action=replace\n\n" >> $script
  done

  printf "cd .." >> $script
  chmod 777 $script
  cd ..

  printf "*** done with ref data install script ***\n\n"

fi

################################################################################

if [ -d functions ]
then

  printf "*** creating functions install script ***\n\n"

  script=functions/install
  rm -fr ${script}.sql

  printf "/* install script generated on " >> $script
  now=`date`
  printf "$now" >> $script
  printf " by my tiny script */\n\n" >> $script
  printf "whenever sqlerror exit failure\n" >> $script
  for file in `ls -1 functions/*.[Ss][Qq][Ll] | sort -g`
  do
    printf "prompt installing $file\n" >> $script
    printf "@" >> $script
    printf "$file\n" >> $script
    printf "prompt installed $file\n" >> $script
  done
  printf "exit success\n" >> $script

  printf "\ncommit;" >> $script
  printf "\nexit;\n" >> $script
  mv $script ${script}.sql
  printf "*** done with functions install script ***\n\n"

fi

################################################################################

if [ -d scripts ]
then

  printf "*** creating stored procedures install script ***\n\n"

  script=scripts/install
  rm -fr ${script}.sql

  printf "/* install script generated on " >> $script
  now=`date`
  printf "$now" >> $script
  printf " by my tiny script */\n\n" >> $script
  printf "whenever sqlerror exit failure\n" >> $script
  for file in `ls -1 scripts/*.[Ss][Qq][Ll] | sort -g`
  do
    printf "prompt installing $file\n" >> $script
    printf "@" >> $script
    printf "$file\n" >> $script
    printf "prompt installed $file\n" >> $script
  done
  printf "exit success\n" >> $script

  printf "\ncommit;" >> $script
  printf "\nexit;\n" >> $script
  mv $script ${script}.sql
  printf "*** done with stored procedures install script ***\n\n"

fi

################################################################################

printf "*** determining data_pump_dir ***\n\n"
DATA_PUMP_DIR=`sqlplus / as sysdba @determineDataPumpDir.sql | grep "dpdump"`
export DATA_PUMP_DIR

if [ -d schema ]
then
  printf "*** installing schema ***\n\n"
  sqlplus / as sysdba @schema/install.sql
  if [ "$?" -eq 0 ]
  then
    echo "**********          schema install sucess           **********"
  else
    echo "**********          schema install failure          **********"
  fi
fi

echo

if [ -d ref-data ]
then
  printf "*** installing ref data ***\n\n"
  ref-data/install.sh
fi

echo

if [ -d functions ]
then
  printf "*** installing functions ***\n\n"
  sqlplus / as sysdba @functions/install.sql
  if [ "$?" -eq 0 ]
  then
    echo "**********          functions install sucess           **********"
  else
    echo "**********          functions install failure          **********"
  fi
fi

echo

if [ -d scripts ]
then
  printf "*** installing stored prcedures ***\n\n"
  sqlplus / as sysdba @scripts/install.sql
  if [ "$?" -eq 0 ]
  then
    echo "**********          scripts install sucess           **********"
  else
    echo "**********          scripts install failure          **********"
  fi
fi

printf "*** all done :) ***\n\n"

cd "$currDir"


Last edited by Scott; 01-06-2010 at 01:56 PM.. Reason: Code tags, please!
# 11  
Old 01-06-2010
I just read the first lines
Code:
#/bin/bash

# determine the directory containing this script
packgeDir=`echo $0 | awk -F 'install.sh' '{print $1}'`
currDir=$PWD

cd "$packgeDir"

seems you need run the script by bash, then run the script by absolute path of install.sh

such as:

Code:
bash /abc/efg/hij/install.sh

Third, you can change your script to

Code:
packgeDir=`dirname $0`
currDir=$PWD

cd $packgeDir

# 12  
Old 01-06-2010
The shebang is also wrong.

Code:
#/bin/bash

should be
Code:
#!/bin/bash

# 13  
Old 01-07-2010
Quote:
Originally Posted by rdcwayx
I just read the first lines
Code:
#/bin/bash

# determine the directory containing this script
packgeDir=`echo $0 | awk -F 'install.sh' '{print $1}'`
currDir=$PWD

cd "$packgeDir"

seems you need run the script by bash, then run the script by absolute path of install.sh

such as:

Code:
bash /abc/efg/hij/install.sh

Third, you can change your script to

Code:
packgeDir=`dirname $0`
currDir=$PWD

cd $packgeDir


I tried using
Code:
packgeDir=`dirname $0'

in the script as you suggested.. and still get the same errors...

I also tried running with the entire path:

Code:
sh /abc/efg/install.sh

but no luck with that either...

---------- Post updated at 01:16 PM ---------- Previous update was at 01:15 PM ----------

Quote:
Originally Posted by scottn
The shebang is also wrong.

Code:
#/bin/bash

should be
Code:
#!/bin/bash


I tried using the correct shebang as you suggested:

Code:
#!/bin/bash

but got no success with that.

---------- Post updated at 01:20 PM ---------- Previous update was at 01:16 PM ----------

Even if i pretend to make some changes in the file.... like for example opening install.sh, then putting a space somewhere in the file, then deleting that space, and saving that file,.... then it works when I type the command:

Code:
sh install.sh


It is only when I am trying to run it directly after unzipping it from the jar file, that I am not able to run it successfully.

So, is it corrupting it while unzipping it, or maybe not recognizing the file is in the directory, until I pretend to move or change it?... not sure.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to encrypt the xls file using executable jar in Linux SUSE 11.4

Dear Experts, I am an ERP consultant and would like to learn shell script. We are working on Linux SUSE 11.4 and I am very new to shell scripting. We can manually encrypt an excel file using "executable jar" through command prompt by placing the jar file & the file to be encrypted on a physical... (1 Reply)
Discussion started by: nithin226
1 Replies

2. Shell Programming and Scripting

Shell file to run other shell files running jar files

Hi, I am trying to write a shell script that will go to another folder and run the script in that folder. The folder structure is kind of like this: /MainFolder/ |-> MainShellScript.sh | |-> Folder1/ |-----|-> script1.sh |-----|-> FileToRun1.jar | |-> Folder2/ |-----|-> script2.sh... (3 Replies)
Discussion started by: sleo
3 Replies

3. Shell Programming and Scripting

Store the name of an extracted file to a temp file

What would be the best way to store the name of an extracted file from a tar to a text file? I want to extract one file from a tar and store the name of the extracted file to a temp file. tar -xvf tar_file.tar file_to_be_extracted (1 Reply)
Discussion started by: erin00
1 Replies

4. Shell Programming and Scripting

Running a script in crontab which executes a jar file

Hi, I have a script (.sh file) which has been created through my login. This script executes a jar file. Java is installed through my login and the folder has been given full permission for access. When this script is added by root in crontab, it does not get executed. Could you please... (1 Reply)
Discussion started by: archana.n
1 Replies

5. Shell Programming and Scripting

unrar - get the name of extracted file

If I have a script that is using unrar e file.part1.rar How does the script get the name of the extracted file if I don't know the extension of the file? In my example the name would be file.***, but I wouldn't know the extension. ---------- Post updated at 05:13 PM ---------- Previous... (0 Replies)
Discussion started by: locoroco
0 Replies

6. Shell Programming and Scripting

include file name to extracted files

I've written the script below to merge only .txt files that exist in one directory into one huge .txt file and ignore other files with other extensions. now the result is one huge .txt file with all the contents of other .txt files how can i add a File Name as a comment before each file? ... (12 Replies)
Discussion started by: miss_dodi
12 Replies

7. UNIX for Dummies Questions & Answers

To send an email with the body content extracted from a file

Hi, I have been trying to shoot an email with the email body to be obtained from a file. Can someone please help me with it.. I have been trying to use the MAILX commad for the same. mailx -s "test email" -r sender@test.com < file.txt but it sends the file as an attachment,while i... (3 Replies)
Discussion started by: rohit.shetty84
3 Replies

8. UNIX for Dummies Questions & Answers

jar command not running in Unix

Hi , I am working in Sun SOlaris 9 and trying to extract a particular jar file in my home. I am giving command "jar xv <filename>" But it just hangs and does nothing ? Any pointers why this is happenning ? or how can I see contents of a jar file? Thanks (2 Replies)
Discussion started by: hkapil
2 Replies

9. UNIX for Dummies Questions & Answers

java.lang.System when running jar

Hello, I recieve the following error when trying to run the following command in a ksh. The operating system is AIX5.1. /usr/bin/jar -xvf {filename}.zip Can't find class java.lang.System But when I run it on the command line it unzips the file fine. Does anybody know why this... (2 Replies)
Discussion started by: ctcuser
2 Replies
Login or Register to Ask a Question