LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Using Dialog in Shell Script (https://www.linuxquestions.org/questions/programming-9/using-dialog-in-shell-script-365677/)

david_ross 09-28-2005 01:19 PM

How about using find:
echo Extracted `find ./ -type f | grep -c ^` files so far

kushalkoolwal 09-30-2005 02:09 PM

Quote:

Originally posted by david_ross
How about using find:
echo Extracted `find ./ -type f | grep -c ^` files so far

I tried your suggestion but I am not able to achieve the output. Perhaps I didn;t understand what are you trying to do. Can you give some more details?

Thank you very very much

vladmihaisima 09-30-2005 05:00 PM

To see how many files are in a tar archive:

Code:

MAX_NR=`tar -tzf 1.tar.gz | wc -l`
To see how many files are in a directory (MAX_NR must be defined, for example with the above command):

Code:

NR=0
while [ $NR -le $MAX_NR ]; do
  NR=`find directory | wc -l` ;
  echo $NR;
  sleep 5 ;
done

Hope I understood corectly what do you want...

kushalkoolwal 10-03-2005 12:51 PM

Quote:

Originally posted by vladmihaisima
To see how many files are in a tar archive:

Code:

MAX_NR=`tar -tzf 1.tar.gz | wc -l`
To see how many files are in a directory (MAX_NR must be defined, for example with the above command):

Code:

NR=0
while [ $NR -le $MAX_NR ]; do
  NR=`find directory | wc -l` ;
  echo $NR;
  sleep 5 ;
done

Hope I understood corectly what do you want...

Thanks buddy. I will try your suggestion and see how it works. Will let you guys know.

thanks once again

kushalkoolwal 10-03-2005 01:27 PM

Quote:

find directory | wc -l
in the above command, I did not understand what do I have to give for the word 'directory'? Should I give the path to my destination directory? Also I did not understand what does the above command do in particular?

My destination directory is /tmp/install-debian i.e. this is the directory in which I am extracting my files from the tar ball.

Also david, for your suggestion of :
Code:

find ./ -type f | grep -c ^
i again did not understand does that command do?

thanks guys for helping me out.

vladmihaisima 10-03-2005 01:37 PM

directory is the absolute path to the directory for which you wish to see how many file are in it.

The command "find directory" lists all the files in the directory, and subdirectories.
The command "wc -l" prints the number of lines it receives.
The "|" (pipe operator) connects the first command output to the second command input.

The second command finds all the files in the current directory (-f switch), and counts them (-c is for count, and as far as I remember ^ for grep is end or start of line).

kushalkoolwal 10-03-2005 03:16 PM

Thanks vladmihaisima and David. It worked. Thank you very very much.

It was good to learn how to get the progress bar for different commands. Guys finally I have one more questions. As I told before I have been using other commans also in my script which takes 30-40 seconds to execute. For Eg. one command is:

Code:

/sbin/grub --no-floppy --batch 1>/dev/null <<EOF
root (hd1,0)
setup (hd1)
quit
EOF

and the other command is
Code:

mke2fs -j -T news /dev/hdd1 1>/dev/null 2>&1
and one more is:
Code:

fsck -f -a /dev/hdd1 1>/dev/null 2>&1
How can I show progress bar using gauge option in dialog for commands like the one above just like we did for tar and cp command in this thread?

Also, it would be a good idea if anyone can suggest a general way of implementing progress bar irrespective of the command given.

Guys thank you once again for all your effort and time.

kushalkoolwal 10-06-2005 02:43 AM

Any one please?

thanks

vladmihaisima 10-06-2005 06:14 AM

I don't think there could be a general way, unless each command provides some kind of feedback. And of course this would introduce a (usually small) performance penalty on the command - and for this reason some people will see this as a bad thing to do.

And about your 3 specific comands I really have no idea how to determine their progress. (and now a Microsoft type idea : you could show a progress bar based on an estimation and that will remain at 99% until the command finished :D - just kidding ).

taiwf 05-01-2007 02:39 AM

Quote:

Originally Posted by david_ross
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








I try to run this script over putty. But it seems to blink alot when progress meter update. Is there anyway i can make it run without screen blinking?

besides , when i resize my putty screen, the meter is gone and i back to command prompt.. Is there be any work around of this issue?

gnashley 05-01-2007 04:20 AM

I spent a lot of time on just such an idea. The algorithm for determining the percentage winds up taking lots more cycles than it was worth and is not very dependable.
You can maybe use tar to get the estimated size of the uncompressed files. Then as the file is uncompressing you keep checking the used disk space with df and comparing that to the full estimated disk space needed. You need to also take into account the speed of the machine and devices being used so you need to also time the unpack process for a given quantity so you can estimate the finish time. Using progress-bar is similar to guage, excpet that progress bar expects a pulsed input -usually a series of dots which are ouputted by the program as it runs. I'd suggest you download the sources for Xdialog as it has some very good examples and the syntax is nearly the same for most widgets.
The slackware installation and configuration utilities are good examples of pure dialog.

taiwf 05-01-2007 06:50 PM

for my case, i have a large file (100G over) to copy. I don't want to the backup operator remote desktop session. So , i would prefer commandline dialog. I have downloaded the slackware11 but not sure which file to look for the installation & configuration dialog? Can you tell me which file to look up (for checking how they do dialog properly).


thanks

gnashley 05-02-2007 11:56 AM

Probably easier to dig around in the sources for Slackware and just download what you need there.
The package called pkgtools is a good place to start.

If you got the installation CD#1 the initrd conatins the installation routines which are written in dialog.

taiwf 06-03-2007 10:59 PM

I have a new problem about keyboard now. My dialog UI easily abort if user press F1~F4 or number pad key.

I look up the 'setup' script in slackware but it doesn't have anything on that script to stop user keyboard input to abort the menu. When i press ESC key on the "no linux partition detect" message box, it simply blink. Can anyone tell me how to achieve so? I don't want user to accidentally drop off from my UI to command prompt.

taiwf 06-03-2007 11:04 PM

i guess i have to use while loop to prevent dropping off from UI...


All times are GMT -5. The time now is 09:23 AM.