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.
|
What do you want to know that isn't covered in the man page?
|
Quote:
|
|
Quote:
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? |
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. |
Quote:
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 |
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.
|
Quote:
Thank you once again. |
This should give a pretty good demonstration but there is no error handling:
Code:
#!/bin/bash |
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. |
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.
|
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 |
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.
|
Quote:
Can you again give me a pseudo code please? Thank you very much.. |
All times are GMT -5. The time now is 07:13 PM. |