Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
|
09-21-2005, 02:56 PM
|
#1
|
|
Senior Member
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249
Rep:
|
Using Dialog in Shell Script
I am trying to write a mini-installer kind of shell script using the dialog utility. Does any one know some good tutorial from their experience which explains using dialog in detail. I googled but I did not find anything useful in particular.
|
|
|
|
09-21-2005, 03:13 PM
|
#2
|
|
Moderator
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047
Rep:
|
What do you want to know that isn't covered in the man page?
|
|
|
|
09-21-2005, 03:39 PM
|
#3
|
|
Senior Member
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249
Original Poster
Rep:
|
Quote:
Originally posted by david_ross
What do you want to know that isn't covered in the man page?
|
Actually I am looking for some good examples. Some times man pages takes loads of time to figure out becase there are hardly examples.
|
|
|
|
09-22-2005, 03:00 AM
|
#4
|
|
Senior Member
Registered: Sep 2003
Location: Egypt
Distribution: Arch
Posts: 1,528
Rep:
|
|
|
|
|
09-23-2005, 10:44 AM
|
#5
|
|
Senior Member
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249
Original Poster
Rep:
|
I am trying to show a progress bar using the dialog utility's gauge option which I found from the following site pointed out by one of the forum memeber
http://www2.linuxjournal.com/article/2460
#!/bin/bash
{ for I in 10 20 30 40 50 60 70 80 90 \
80 70 60 50 40 30 20 10 0; do
echo $I
sleep 1
done
echo; } | dialog --guage "A guage demo" 6 70 0
They have given a very simple example(look above) of implementing the gauge utility. Actually in my script I am copying huge files from one disk to another which takes couple of minutes, so I wanted to show the progress bar while the copying the files using thd dialog utility.
Does any one have any experiences in doing this?
|
|
|
|
09-23-2005, 01:08 PM
|
#6
|
|
Moderator
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047
Rep:
|
All you are really doing is echoing the percentage of the copy done. If you know the number of the files being copied then you just need to make a little formula to know the percentage of the files you have copied:
percent=$(((100/$total)*$filenum))
Where $total is the number of files being copied and $filenum is the filenumber being copied. You would get a more accurate account if you did this by checking the number of bytes transfered compared to the total, although this would require more processing and depending on your situation might not be justified.
|
|
|
|
09-23-2005, 01:45 PM
|
#7
|
|
Senior Member
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249
Original Poster
Rep:
|
Quote:
Originally posted by david_ross
All you are really doing is echoing the percentage of the copy done. If you know the number of the files being copied then you just need to make a little formula to know the percentage of the files you have copied:
percent=$(((100/$total)*$filenum))
Where $total is the number of files being copied and $filenum is the filenumber being copied. You would get a more accurate account if you did this by checking the number of bytes transfered compared to the total, although this would require more processing and depending on your situation might not be justified.
|
Thanks for your suggestion. Yes I have file.tar.bz2 compressed files which have various directories and files(hidden/special/configuration files). Can I some how know the total number of files contained in the tar ball. Is there any utility which will give this information.
Also how will I know which number is being copied? I am using the following command:
debian#cp deb-install.tar.bz2 /tmp/DebianInstall
thanks
Last edited by kushalkoolwal; 09-23-2005 at 01:49 PM.
|
|
|
|
09-23-2005, 02:35 PM
|
#8
|
|
Moderator
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047
Rep:
|
In that case you are only copying one file, the easiest way to do this (since it is a local copy) would be to stat the original file to find it's size, then send the copy command into the background or fork the script, then the dialog script can stat the destination file periodically to find out what size it is and update the dialog acordingly.
|
|
|
|
09-24-2005, 12:11 PM
|
#9
|
|
Senior Member
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249
Original Poster
Rep:
|
Quote:
Originally posted by david_ross
In that case you are only copying one file, the easiest way to do this (since it is a local copy) would be to stat the original file to find it's size, then send the copy command into the background or fork the script, then the dialog script can stat the destination file periodically to find out what size it is and update the dialog acordingly.
|
Thank you so much for giving the idea. Can you please give me a sample code or a Pseudo kind of thing? I am not that familiar with advanced Shell scripting.
Thank you once again.
|
|
|
|
09-24-2005, 01:20 PM
|
#10
|
|
Moderator
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047
Rep:
|
This should give a pretty good demonstration but there is no error handling:
Code:
#!/bin/bash
# Set the source and destination files
srcfile="/tmp/500M.src"
dstfile="/tmp/500M.dst"
# Create a large file for testing with
echo Creating 500M.src as a source file
dd if=/dev/zero of=$srcfile bs=1048576 count=500
srcsize=`stat -c %s $srcfile`
echo Done. Copy will start in 5 seconds
sleep 5
# Remove the destination file if it exists then start to copy
dstsize=0
rm -f $dstfile
cp -f $srcfile $dstfile &
# Check the size every second until both files are the same size
while [ $dstsize -lt $srcsize ];do
dstsize=`stat -c %s $dstfile`
percent=$(((100*$dstsize)/$srcsize))
echo $percent | dialog --guage "Copying $srcfile to $dstfile" 6 70 0
sleep 1
done
|
|
|
|
09-26-2005, 11:02 AM
|
#11
|
|
Senior Member
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249
Original Poster
Rep:
|
Thanks David. It worked!!! I have one more question which is the extension of my copying process. After I copy by tar.bz2 file to my destination, I am extracting the content of the tar bar by the following command:
tar -xjf debian-install-files.tar.bz2
How can I show the progress bar in the gauge for extraction process?
Thank you once again for all your help.
|
|
|
|
09-27-2005, 12:04 PM
|
#12
|
|
Moderator
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047
Rep:
|
I don't think you could easlily find the size of files within the archive so unless you know that before I don't think it would be very easy.
|
|
|
|
09-27-2005, 06:01 PM
|
#13
|
|
Senior Member
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249
Original Poster
Rep:
|
Yes, the tar ball that I am trying to decompress and extract have the same number of files and directory everytime. Now is it possible with this information?
Kushal
|
|
|
|
09-28-2005, 12:22 PM
|
#14
|
|
Moderator
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047
Rep:
|
I would imagine so - just count the number of files extracted compared with the total number in the archive or if you want to do it with the file sizes just stat the files.
|
|
|
|
09-28-2005, 01:10 PM
|
#15
|
|
Senior Member
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249
Original Poster
Rep:
|
Quote:
Originally posted by david_ross
I would imagine so - just count the number of files extracted compared with the total number in the archive or if you want to do it with the file sizes just stat the files.
|
Sorry for being such a pest. But I really don;t know how to implement this i..e how to count number of files extracted and how to find the total number of files in the archieve.
Can you again give me a pseudo code please?
Thank you very much..
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 10:36 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|