LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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



Reply
 
Search this Thread
Old 09-21-2005, 03:56 PM   #1
kushalkoolwal
Senior Member
 
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249

Rep: Reputation: 48
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.
 
Old 09-21-2005, 04:13 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 65
What do you want to know that isn't covered in the man page?
 
Old 09-21-2005, 04:39 PM   #3
kushalkoolwal
Senior Member
 
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249

Original Poster
Rep: Reputation: 48
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.
 
Old 09-22-2005, 04:00 AM   #4
heema
Senior Member
 
Registered: Sep 2003
Location: Egypt
Distribution: Arch
Posts: 1,528

Rep: Reputation: 46
Here is a dialog HowTo

http://www2.linuxjournal.com/article/2460
 
Old 09-23-2005, 11:44 AM   #5
kushalkoolwal
Senior Member
 
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249

Original Poster
Rep: Reputation: 48
Quote:
Originally posted by heema
Here is a dialog HowTo

http://www2.linuxjournal.com/article/2460

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?
 
Old 09-23-2005, 02:08 PM   #6
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 65
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.
 
Old 09-23-2005, 02:45 PM   #7
kushalkoolwal
Senior Member
 
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249

Original Poster
Rep: Reputation: 48
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 02:49 PM.
 
Old 09-23-2005, 03:35 PM   #8
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 65
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.
 
Old 09-24-2005, 01:11 PM   #9
kushalkoolwal
Senior Member
 
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249

Original Poster
Rep: Reputation: 48
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.
 
Old 09-24-2005, 02:20 PM   #10
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 65
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
 
Old 09-26-2005, 12:02 PM   #11
kushalkoolwal
Senior Member
 
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249

Original Poster
Rep: Reputation: 48
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.
 
Old 09-27-2005, 01:04 PM   #12
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 65
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.
 
Old 09-27-2005, 07:01 PM   #13
kushalkoolwal
Senior Member
 
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249

Original Poster
Rep: Reputation: 48
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
 
Old 09-28-2005, 01:22 PM   #14
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 65
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.
 
Old 09-28-2005, 02:10 PM   #15
kushalkoolwal
Senior Member
 
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249

Original Poster
Rep: Reputation: 48
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..
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script inside shell script treotan Linux - General 4 02-19-2009 07:34 AM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 03:14 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 06:32 PM
Making shell scripts interactive using dialog saurabh142857 Programming 2 01-03-2005 12:14 PM
shell script with dialog sqn Programming 3 04-08-2004 03:25 PM


All times are GMT -5. The time now is 08:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration