?
Solved

shell script to be debugged

Posted on 2005-03-03
45
Medium Priority
?
828 Views
Last Modified: 2010-04-21
this script has a problem , the problem is after giving the file_name
it is supposed to show the extraction progress but it doesnt , some one debug this and make it better
500 easy points to the one who does it today


#!/bin/bash

file_name="your-java-tar-name.tar"

file_size=`ls -l $file_name | awk '{ print $5 }'`
# Getting the exact file size in bytes
filekb=`echo "$file_size/1024" | bc`
# converting that into kilobytes
ini_fs_size=`df -k . | awk '{ print $3 }' | grep -v Used`
# getting the current filesystem size where your extracting
# the file .

percentage=0
final_percent=100
tar -xf $file_name &

{ while [ "$percentage" -lt $final_percent  ]
do
  latter_fs_size=`df -k . | awk '{ print $3 }' | grep -v Used`
# After extracting started get the filesystem size every second
# and the do a small math
  percent_val=`expr $latter_fs_size - $ini_fs_size`
# Get the difference between intial and current filestem space
  percentage=`echo "($percent_val * 100)/$filekb" | bc`
# get the precentage of it with respect to original file size
  if [ "$percentage" -gt $final_percent ]
  then
    echo $final_percent
  else
    echo $percentage
  fi
# the above if loop si to cover up just in case
  sleep 1
done } | dialog --guage "Uncompressing status" 6 70 0
clear
0
Comment
Question by:pencil123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 25
  • 10
  • 7
  • +1
45 Comments
 
LVL 3

Expert Comment

by:AndyWHV
ID: 13450340
dialog --guage "Uncompressing status" 6 70 0

has to be dialog --gauge

that is what i can see immediately .... if theres more - let me know
0
 
LVL 3

Expert Comment

by:AndyWHV
ID: 13450598
seems to work - i modified it a bit, that you can also use it with .tar.gz files:

#!/bin/bash

file_name="your-tar-gz-name.tar.gz"

file_size=`gunzip -l $file_name | awk '{ print $2 }' | grep -v uncompressed`
# Getting the exact file size in bytes
filekb=`echo "$file_size/1024" | bc`
# converting that into kilobytes
ini_fs_size=`df -k . | awk '{ print $3 }' | grep -v Used`
# getting the current filesystem size where your extracting
# the file .

percentage=0
final_percent=100
tar -xzf $file_name &

{
while [ "$percentage" -lt $final_percent  ]
do
    latter_fs_size=`df -k . | awk '{ print $3 }' | grep -v Used`
    # After extracting started get the filesystem size every second
    # and the do a small math
    percent_val=`expr $latter_fs_size - $ini_fs_size`
    # Get the difference between intial and current filestem space
    percentage=`echo "($percent_val * 100)/$filekb" | bc`
    # get the precentage of it with respect to original file size
    if [ "$percentage" -gt $final_percent ]
    then
        echo $final_percent
    else
        echo $percentage
    fi
    # the above if loop si to cover up just in case
    sleep 1
done
} | dialog --gauge "Uncompressing status" 6 70 0

clear
0
 
LVL 7

Expert Comment

by:surya_prabhakar
ID: 13451821
Pencil123:
    What is wrong with the script .It was working fine before right? are you getting any errors .

AndyWHv:
    it is not making any difference gauge or guage .


surya.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 51

Expert Comment

by:ahoffmann
ID: 13452688
to debug your script use inside (wher you want debugging to be started):

set -x
0
 
LVL 3

Expert Comment

by:AndyWHV
ID: 13452788
oh...maybe i know what your problem is....is it that you can't see that there is a progress on small files ?

you could change the sleep to
sleep 0.1

so it will show up more often
0
 

Author Comment

by:pencil123
ID: 13456934
still the script isnt working, it just stops with cursor blinking

has any1 checked and tested the script

i hv mentioned the problem at the beginning itself
0
 

Author Comment

by:pencil123
ID: 13456935
surya_prabhakar : its not working
0
 

Author Comment

by:pencil123
ID: 13456942
it just hangs
the n i hv to do a ctrl-c
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 13456957
please use
  set -x

and then tell us wher it hangs

"its not working" and "it just hangs" are useless infomration, please be more specific so we can help you
0
 

Author Comment

by:pencil123
ID: 13456972
k found the problem
the filename directory shouldnt exists

i found the bug

thanx for trying
0
 

Author Comment

by:pencil123
ID: 13456973
lol
0
 

Author Comment

by:pencil123
ID: 13457025
: [: : integer expression expected
0
 
LVL 7

Expert Comment

by:surya_prabhakar
ID: 13457032
Yes! if it already exists - the filesystem size is same before and now hence the progress bar will not move .

surya.
0
 
LVL 7

Expert Comment

by:surya_prabhakar
ID: 13457041
please do what ahoffmann said . need more information  :-)
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 13457084
(test -z "$file_name" || test -z "$filekb" || test -z "$ini_fs_size" || test -z "$latter_fs_size")&& exit 1
0
 

Author Comment

by:pencil123
ID: 13457122
ok sorry for that
i need it for extracting .war files also

i replaced tar -xzf $file_name & with
   jar -xf $file_name &

its giving some integer expression expected

what to do
0
 
LVL 7

Expert Comment

by:surya_prabhakar
ID: 13457274
war files ????????
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 13457305
> its giving some integer expression expected
> what to do
more and more your comments get anoying ...
how should we help you if you don't provide detailed infomation?
What is the problem with copy&paste the error messages verbatim?
why do you not follow the suggestions?
0
 

Author Comment

by:pencil123
ID: 13457367
well i think thats what i did

the only problem i have now is extracting .wat files
they stand for web archive

ok here i will paste the whole code
#!/bin/sh

file_name="somefile.war"

file_size=`ls -l $file_name | awk '{ print $2 }' | grep -v uncompressed`
# Getting the exact file size in bytes
filekb=`echo "$file_size/1024" | bc`
# converting that into kilobytes
ini_fs_size=`df -k . | awk '{ print $3 }' | grep -v Used`
# getting the current filesystem size where your extracting
# the file .

percentage=0
final_percent=100
jar -xzf $file_name &

{
while [ "$percentage" -lt $final_percent  ]
do
    latter_fs_size=`df -k . | awk '{ print $3 }' | grep -v Used`
    # After extracting started get the filesystem size every second
    # and the do a small math
    percent_val=`expr $latter_fs_size - $ini_fs_size`
    # Get the difference between intial and current filestem space
    percentage=`echo "($percent_val * 100)/$filekb" | bc`
    # get the precentage of it with respect to original file size
    if [ "$percentage" -gt $final_percent ]
    then
        echo $final_percent
    else
        echo $percentage
    fi
    # the above if loop si to cover up just in case
    sleep 1
done
} | dialog --gauge "Uncompressing status" 6 70 0

clear

0
 
LVL 7

Expert Comment

by:surya_prabhakar
ID: 13457370
Pencil :
    Please provide full details .  we have our own daily routines to do here apart from helping .
If you are not helping us - to help you then it would become absolutely impossible .

Please dont get into a situation where people stop helping you as soon as they see your name .

0
 

Author Comment

by:pencil123
ID: 13457375
i hope this is clear enuf
0
 

Author Comment

by:pencil123
ID: 13457384
sorry i m under a lot of pressure
also i havent had sleep properly
i m tring my best
i hv pasted the whole code
now it shud work with .war files aswell
plz take a look at it
0
 

Author Comment

by:pencil123
ID: 13457406
if i put
            jar -x $file_name &
i get this


│Runtime error (func=(main), adr=9): Divide by zero            │  │
                           │  └──────────────────────────────────────────────────./test.sh: line 27: [: : integer expression
expected                   └────────────────────────────────────────────────────────────────────┘
        ./test.sh: line 18: [: : integer expression expected
                                                                                                                             
0
 

Author Comment

by:pencil123
ID: 13457431
well i guess no ones gonna help me now

 i m sorry

0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 13457461
pencil123, please reread http:#13457305
then sit down and think about it
then read again http:#13457305
try to understabnd it, if in doubt about any question there, ask what's the problem about it

we can't help you if you don't give the requested information

to fix your errors see http:#13452688  and http:#13457084
all answers have been given, if it does not work for you you made a mistake, typed it wrong or whatever. Dot.
0
 

Author Comment

by:pencil123
ID: 13457480
i put set -x
since i m using dialog i cant see the errors

also i do get this
 Runtime error (func=(main), adr=9): Divide by zero
what does it mean

0
 

Author Comment

by:pencil123
ID: 13457490
all i want now is that the script should work with .war files

but it isnt

thats all ineed
0
 

Author Comment

by:pencil123
ID: 13457518
please make the script work with .war files

thats all i need
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 13457581
> Runtime error (func=(main), adr=9): Divide by zero
does your jar command work from command-line with that file?
0
 

Author Comment

by:pencil123
ID: 13457582
can anyone help me now

i cant make the problem more clear

i dont think u need any sort of info , u have the script , make it work with .war files

.war files are web archive files
jar extraction utility is used for that

what else info is needed
0
 

Author Comment

by:pencil123
ID: 13457587
> Runtime error (func=(main), adr=9): Divide by zero
does your jar command work from command-line with that file?

yes it does work from the command line

0
 

Author Comment

by:pencil123
ID: 13457671
just so u know

all i want is that the script should work with .war files
that   dot war

.WAR
and jar is a utility used for extracting war files

0
 
LVL 7

Expert Comment

by:surya_prabhakar
ID: 13457685
run this ... it creates an output file called out_file in the same directory . paste the contents of the file here

#!/bin/sh
file_name="somefile.war"
file_size=`ls -l $file_name | awk '{ print $2 }' | grep -v uncompressed`
echo "file size is .....$file_size"  >> out_file
filekb=`echo "$file_size/1024" | bc`
echo "file size in kb ..... $filekb" >> out_file
ini_fs_size=`df -k . | awk '{ print $3 }' | grep -v Used`
echo "Inital fs size ...... $ini_fs_size" >> out_file
percentage=0
final_percent=100
jar -xvf $file_name &
{
while [ "$percentage" -lt $final_percent  ]
do
    latter_fs_size=`df -k . | awk '{ print $3 }' | grep -v Used`
    echo "latter fs size .... $latter_fs_size" >> out_file
    percent_val=`expr $latter_fs_size - $ini_fs_size`
    echo "percent  val is ....$percent_val" >> out_file
    percentage=`echo "($percent_val * 100)/$filekb" | bc`
    echo "percentage value ....$percentage" >> out_file
    if [ "$percentage" -gt $final_percent ]
    then
        echo $final_percent
    else
        echo $percentage
    fi
    sleep 1
done
} | dialog --gauge "Uncompressing status" 6 70 0
clear
0
 
LVL 7

Expert Comment

by:surya_prabhakar
ID: 13457696
forgot ....
> jar -xvf $file_name &
change it to
jar -xf $file_name &
0
 

Author Comment

by:pencil123
ID: 13457708
file size is .....
file size in kb .....
Inital fs size ...... 10939584
latter fs size .... 10939584
percent  val is ....0
percentage value ....
~
~
0
 

Author Comment

by:pencil123
ID: 13457725
wiht jar -xf $filename &

file size is .....
file size in kb .....
Inital fs size ...... 10939592
latter fs size .... 10939592
percent  val is ....0
percentage value ....
~
~
~
0
 
LVL 7

Expert Comment

by:surya_prabhakar
ID: 13457758
Why did you change the shell from bin/bash to bin/sh . dont change the below script except for the filename
save it as file and put permissions as
#chmod 755 <filename>  and then run it as
# ./filename    ( before you do this - remove the previously existing directory )

-------------------------------------------------------------------
#!/bin/bash
file_name="filename.war"
file_size=`ls -l $file_name | awk '{ print $5 }'`
filekb=`echo "$file_size/1024" | bc`
ini_fs_size=`df -k . | awk '{ print $3 }' | grep -v Used`
percentage=0
final_percent=100
jar -xf $file_name &

{ while [ "$percentage" -lt $final_percent  ]
do
  latter_fs_size=`df -k . | awk '{ print $3 }' | grep -v Used`
  percent_val=`expr $latter_fs_size - $ini_fs_size`
  percentage=`echo "($percent_val * 100)/$filekb" | bc`
  if [ "$percentage" -ge $final_percent ]
  then
    echo $final_percent
  else
    echo $percentage
  fi
  sleep 1
done } | dialog --gauge "A Progress bar" 6 70 0
clear
-------------------------------------------------------------------
0
 

Author Comment

by:pencil123
ID: 13457790
i did as u said

but when i ran it
it said line number 18 has some problem
i check line number 18
it is
  if [ "$percentage" -ge $final_percent ]

also i can get the whole error output since i m using dialog
i m sorry


0
 
LVL 7

Expert Comment

by:surya_prabhakar
ID: 13457827
listen ... cool down for a minute - if u be in constant pressure u will commit basic mistakes .

first check the above script with tar file and tell whether it is working or not . Then we can think of jar .
script errors to be avoided first . This exact script is working firne for me ...
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 960 total points
ID: 13457919
> file_size=`ls -l $file_name | awk '{ print $2 }' | grep -v uncompressed`
don't know where you get this, should probably be:
   file_size=`ls -l $file_name | awk '{ print $5 }'`
0
 

Author Comment

by:pencil123
ID: 13457988
it works fine for tar files
no problems with that

it doesnt work with war files
thats the only problem left

0
 

Author Comment

by:pencil123
ID: 13458006
ahoffmann

that is not a problem
i m running it with
file_size=`ls -l $file_name | awk '{ print $5 }'`
when i say

jar -x filename.war in command line
it extracts fine

the problem is in the script
when i try to do the same
0
 
LVL 7

Assisted Solution

by:surya_prabhakar
surya_prabhakar earned 40 total points
ID: 13458016
Believe me the below script is working good - I downloaded java now and used a jar to extract a file.jar and it showed me progress
---------------------------------------
#!/bin/bash
file_name="filename.jar"
file_size=`ls -l $file_name | awk '{ print $5 }'`
filekb=`echo "$file_size/1024" | bc`
ini_fs_size=`df -k . | awk '{ print $3 }' | grep -v Used`
percentage=0
final_percent=100
jar -xf $file_name &
{ while [ "$percentage" -lt $final_percent  ]
do
  latter_fs_size=`df -k . | awk '{ print $3 }' | grep -v Used`
  percent_val=`expr $latter_fs_size - $ini_fs_size`
  percentage=`echo "($percent_val * 100)/$filekb" | bc`
  if [ "$percentage" -ge $final_percent ]
  then
    echo $final_percent
  else
    echo $percentage
  fi
  sleep 0.0001
done } | dialog --gauge "A Progress bar" 6 70 0
clear
------------------------------------------------------------------------------
if it doesnot work then something is wrong in your system - check whether you are using bash or sh .
I really dont know what is that .war thing whether it works with jar extraction or not .
that's all from my side.

surya.
0
 

Author Comment

by:pencil123
ID: 13458032
it works fine with .jar as well
i know that

but i need to work it with .war(web archive)
.jar is for java archive

.war  files are used to package a web application directory  structure
ofcourse they do contain java files and stuff
but thats not the pont

please try getting a .war file from somewhere and try to check it

thanks





0
 

Author Comment

by:pencil123
ID: 13458050
.war files are extracted with the jar utility itself
so it should work
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

764 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