Question

shell script to be debugged

Asked by: pencil123

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

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2005-03-03 at 03:29:15ID21336081
Tags

bash

,

dialog

,

tar

Topic

Linux Programming

Participating Experts
3
Points
500
Comments
45

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. passing $var(korn shell var) to awk
    how do you pass $var to awk:- see below for var in `ls *.gz` do echo $var zcat $var | grep "HTML" | awk '{printf ("%s===>%s,(need $var here),$0)}' done how do i get $var into awk as it contains the file name, the output should look like: filen...
  2. Awk Script help
    I am dumbo to scripting. can any one tell me how to assign values to variables in awk and shell script For example ls -al | grep test | awk '{print $8}' returns a value. Instead of printing $8 I would like to assign it to a variable val. All that I want is retrieve t...
  3. awk in shell script
    I can get the day of the month when a file, say /etc/hosts here, was updated by the following command line: # ls -l /etc/hosts | awk '{print $7}' My question is how to put it in "sh -c" syntax. I dont' want to creat a shell script file. And the one as follo...
  4. bash script variables
    in a script i am writing i need to get a listing of files witin a directory, the returned value's should be one per line as i then grep for the owner. Once i have the owner i grep for that name within a master list of users to get the full username to pass against an email d...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: AndyWHVPosted on 2005-03-03 at 07:38:37ID: 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

 

by: AndyWHVPosted on 2005-03-03 at 07:59:00ID: 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

 

by: surya_prabhakarPosted on 2005-03-03 at 09:55:17ID: 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.

 

by: ahoffmannPosted on 2005-03-03 at 11:37:26ID: 13452688

to debug your script use inside (wher you want debugging to be started):

set -x

 

by: AndyWHVPosted on 2005-03-03 at 11:50:31ID: 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

 

by: pencil123Posted on 2005-03-04 at 00:44:44ID: 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

 

by: pencil123Posted on 2005-03-04 at 00:45:14ID: 13456935

surya_prabhakar : its not working

 

by: pencil123Posted on 2005-03-04 at 00:46:04ID: 13456942

it just hangs
the n i hv to do a ctrl-c

 

by: ahoffmannPosted on 2005-03-04 at 00:49:18ID: 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

 

by: pencil123Posted on 2005-03-04 at 00:53:17ID: 13456972

k found the problem
the filename directory shouldnt exists

i found the bug

thanx for trying

 

by: pencil123Posted on 2005-03-04 at 00:53:54ID: 13456973

lol

 

by: pencil123Posted on 2005-03-04 at 01:06:34ID: 13457025

: [: : integer expression expected

 

by: surya_prabhakarPosted on 2005-03-04 at 01:07:56ID: 13457032

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

surya.

 

by: surya_prabhakarPosted on 2005-03-04 at 01:11:01ID: 13457041

please do what ahoffmann said . need more information  :-)

 

by: ahoffmannPosted on 2005-03-04 at 01:24:38ID: 13457084

(test -z "$file_name" || test -z "$filekb" || test -z "$ini_fs_size" || test -z "$latter_fs_size")&& exit 1

 

by: pencil123Posted on 2005-03-04 at 01:33:25ID: 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

 

by: surya_prabhakarPosted on 2005-03-04 at 02:01:12ID: 13457274

war files ????????

 

by: ahoffmannPosted on 2005-03-04 at 02:06:28ID: 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?

 

by: pencil123Posted on 2005-03-04 at 02:17:16ID: 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

 

by: surya_prabhakarPosted on 2005-03-04 at 02:17:29ID: 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 .

 

by: pencil123Posted on 2005-03-04 at 02:18:08ID: 13457375

i hope this is clear enuf

 

by: pencil123Posted on 2005-03-04 at 02:19:37ID: 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

 

by: pencil123Posted on 2005-03-04 at 02:23:27ID: 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
                                                                                                                             

 

by: pencil123Posted on 2005-03-04 at 02:27:14ID: 13457431

well i guess no ones gonna help me now

 i m sorry

 

by: ahoffmannPosted on 2005-03-04 at 02:32:01ID: 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.

 

by: pencil123Posted on 2005-03-04 at 02:36:38ID: 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

 

by: pencil123Posted on 2005-03-04 at 02:37:48ID: 13457490

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

but it isnt

thats all ineed

 

by: pencil123Posted on 2005-03-04 at 02:42:19ID: 13457518

please make the script work with .war files

thats all i need

 

by: ahoffmannPosted on 2005-03-04 at 02:56:57ID: 13457581

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

 

by: pencil123Posted on 2005-03-04 at 02:57:04ID: 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

 

by: pencil123Posted on 2005-03-04 at 02:57:51ID: 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

 

by: pencil123Posted on 2005-03-04 at 03:13:51ID: 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

 

by: surya_prabhakarPosted on 2005-03-04 at 03:16:42ID: 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

 

by: surya_prabhakarPosted on 2005-03-04 at 03:20:10ID: 13457696

forgot ....
> jar -xvf $file_name &
change it to
jar -xf $file_name &

 

by: pencil123Posted on 2005-03-04 at 03:22:58ID: 13457708

file size is .....
file size in kb .....
Inital fs size ...... 10939584
latter fs size .... 10939584
percent  val is ....0
percentage value ....
~
~

 

by: pencil123Posted on 2005-03-04 at 03:24:48ID: 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 ....
~
~
~

 

by: surya_prabhakarPosted on 2005-03-04 at 03:31:11ID: 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
-------------------------------------------------------------------

 

by: pencil123Posted on 2005-03-04 at 03:37:58ID: 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


 

by: surya_prabhakarPosted on 2005-03-04 at 03:45:27ID: 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 ...

 

by: ahoffmannPosted on 2005-03-04 at 04:00:39ID: 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 }'`

 

by: pencil123Posted on 2005-03-04 at 04:08:33ID: 13457988

it works fine for tar files
no problems with that

it doesnt work with war files
thats the only problem left

 

by: pencil123Posted on 2005-03-04 at 04:10:44ID: 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

 

by: surya_prabhakarPosted on 2005-03-04 at 04:11:44ID: 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.

 

by: pencil123Posted on 2005-03-04 at 04:14:34ID: 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





 

by: pencil123Posted on 2005-03-04 at 04:15:47ID: 13458050

.war files are extracted with the jar utility itself
so it should work

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...