LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 06-29-2004, 04:35 AM   #1
Voyager_MP
LQ Newbie
 
Registered: Jun 2004
Location: Aachen, Germany
Distribution: Debian sarge
Posts: 23

Rep: Reputation: 15
While Schleife


Hi, need some help with an test argument in while

I need to run some things while dd is working

while [ while programm (dd) runs ] ; do ...
^^^^^^^^^^^^^^^^^^^^^
How do I do this ?


By the way does anyone now how to get a progress bar on dd ?
 
Old 06-29-2004, 05:15 AM   #2
Goala
Member
 
Registered: May 2004
Location: Merida (Spain)
Distribution: Debian
Posts: 89

Rep: Reputation: 15
you can try...

Code:
RETURN=0
until [ $RETURN -ne 0 ]
do
   ps -fea | grep dd
   RETURN=$?
   sleep 1
done
 
Old 06-29-2004, 07:13 AM   #3
Voyager_MP
LQ Newbie
 
Registered: Jun 2004
Location: Aachen, Germany
Distribution: Debian sarge
Posts: 23

Original Poster
Rep: Reputation: 15
I dont seem to get it, how shall that work ?
Here is the complet script. What I need is a progress bar for dd

red='\e[0;31m'
NC='\e[0m'
green='\e[1;32m'
folder="/externhdd/michel"

if [ -d /externhdd/michel ]; then
echo -n "Backup wird ausgeführt..."
nice -n 19 dd if=/dev/hda of=$folder/`date +%d.%m.%Y`.img
RETURN=0
until [ $RETURN -ne 0 ]; do
ps -fea | grep dd
RETURN=$?
sleep 1
done
chmod 600 -Rf $folder/`date +%d.%m.%Y`.img
if [ -e $folder/`date +%d.%m.%Y`.img ]; then
echo -n -e ${green}"done"${NC}
else
echo -n -e ${red}"FAILED"${NC}
fi
else
mount /externhdd
echo -n "Backup wird ausgeführt..."
nice -n 19 dd if=/dev/hda of=$folder/`date +%d.%m.%Y`.img
chmod 600 -Rf $folder/`date +%d.%m.%Y`.img
if [ -e $folder/`date +%d.%m.%Y`.img ]; then
echo -n -e ${green}"done"${NC}
else
echo -n -e ${red}"FAILED"${NC}
fi
fi
 
Old 06-29-2004, 10:23 AM   #4
Goala
Member
 
Registered: May 2004
Location: Merida (Spain)
Distribution: Debian
Posts: 89

Rep: Reputation: 15
Hi Voyager, sorry but I have not explained myself.

First, you must run dd command in the background:

nice -n 19 dd if=/dev/hda of=$folder/`date +%d.%m.%Y`.img &

(note the & character at the end of the line)

It lets the script continue running (and doing anything else), and don't wait for dd to end.

Then, You come into the until loop. This loop will be executing while dd is running. You can place code after the sleep instruction. If you know the final size (more or less) of the .img file, you can test the .img file size every 1 (or more) seconds and show a percentage, megabytes written/left or anything else.

One thing more, use grep (in the until loop) with -q option (quiet, no output).

somewhat more clear?
 
Old 06-30-2004, 12:18 PM   #5
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Use kill -SIGUSR1 to have dd output how much it has copied so far.
From the man page of "dd":
Quote:
Note that sending a SIGUSR1 signal to a running `dd' process makes it
print to standard error the number of records read and written so far,
then to resume copying.

$ dd if=/dev/zero of=/dev/null& pid=$!
$ kill -USR1 $pid; sleep 1; kill $pid

10899206+0 records in 10899206+0 records out
I'll leave parsing its output to you

Last edited by Hko; 06-30-2004 at 12:19 PM.
 
  


Reply



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



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:17 AM.

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
Open Source Consulting | Domain Registration