shell script question (not basic)
All, I've written a shell script and it basically works, but not quite. I have a bug, a scripting question, and a 'parted' desire. First the bug: The wait command below is not working. If I inline the function 'clean_a_drive', the wait command works as expected. How can I make wait actually pause until all the background functions are complete. If inlining the code is the only way, that will obviously be acceptable, it just seems like there ought to be a way to do this. Now the concern: In the function, what is the scope of the variables. I want them to be local to the function and I think they are, but I'm concerned they may be global, I may end up having the wrong size partitions created if I have drives of different sizes that I'm wiping. And the desire: I wish there were a simple way to create the partition as large as possible and not have to pass in the size in MEGS to parted. By using megs, I loosing a little bit of useable space at the end of the drive. (I know not enough to worry about. === #!/bin/sh set -x function clean_a_drive ( ) { #wipe the drive with zeros dd if=/dev/zero of=/dev/$1 bs=256k & #determine how many Megs the drive is SECTORS=`cat /proc/ide/$1/capacity` KB=`expr $SECTORS / 2` MEGS=`expr $KB / 1024` #create a partition table parted -s /dev/$1 mklabel msdos #create a FAT32 partition the full size of the drive, don't format yet parted -s /dev/$1 mkpart primary FAT32 0 $MEGS mkdosfs -F 32 -n EVIDENCE /dev/hdc1 } #Clean the drives for drive in hdc hde hdg hdi do if [ -e /proc/ide/$drive ] then echo cleaning $drive clean_a_drive $drive fi & done wait # this is NOT working exit === Thanks Greg
Please ignore the "wait" bug below. It was my error.
ie. the & on the end of dd line was not supposed to be there.
I'm still curious about variable scope and a better way to invoke parted.
Thanks
Greg
On Thu, 6 Jan 2005 16:40:51 -0500, Greg Freemyer
All,
I've written a shell script and it basically works, but not quite.
I have a bug, a scripting question, and a 'parted' desire.
First the bug: The wait command below is not working.
If I inline the function 'clean_a_drive', the wait command works as expected.
How can I make wait actually pause until all the background functions are complete. If inlining the code is the only way, that will obviously be acceptable, it just seems like there ought to be a way to do this.
Now the concern: In the function, what is the scope of the variables. I want them to be local to the function and I think they are, but I'm concerned they may be global, I may end up having the wrong size partitions created if I have drives of different sizes that I'm wiping.
And the desire: I wish there were a simple way to create the partition as large as possible and not have to pass in the size in MEGS to parted. By using megs, I loosing a little bit of useable space at the end of the drive. (I know not enough to worry about.
=== #!/bin/sh
set -x
function clean_a_drive ( ) { #wipe the drive with zeros dd if=/dev/zero of=/dev/$1 bs=256k &
#determine how many Megs the drive is SECTORS=`cat /proc/ide/$1/capacity` KB=`expr $SECTORS / 2` MEGS=`expr $KB / 1024`
#create a partition table parted -s /dev/$1 mklabel msdos
#create a FAT32 partition the full size of the drive, don't format yet parted -s /dev/$1 mkpart primary FAT32 0 $MEGS
mkdosfs -F 32 -n EVIDENCE /dev/hdc1 }
#Clean the drives for drive in hdc hde hdg hdi do if [ -e /proc/ide/$drive ] then echo cleaning $drive clean_a_drive $drive fi & done
wait # this is NOT working
exit ===
Thanks Greg
* Greg Freemyer
First the bug: The wait command below is not working.
If I inline the function 'clean_a_drive', the wait command works as expected.
How can I make wait actually pause until all the background functions are complete. If inlining the code is the only way, that will obviously be acceptable, it just seems like there ought to be a way to do this.
man lockfile in fact, this was just discussed three or four days ago, here. -- Patrick Shanahan Registered Linux User #207535 http://wahoo.no-ip.org @ http://counter.li.org HOG # US1244711 Photo Album: http://wahoo.no-ip.org/photos
On Thu, 6 Jan 2005 17:06:41 -0500, Patrick Shanahan
* Greg Freemyer
[01-06-05 16:42]: First the bug: The wait command below is not working.
If I inline the function 'clean_a_drive', the wait command works as expected.
How can I make wait actually pause until all the background functions are complete. If inlining the code is the only way, that will obviously be acceptable, it just seems like there ought to be a way to do this.
man lockfile
in fact, this was just discussed three or four days ago, here. -- Patrick Shanahan Registered Linux User #207535
Patrick, As I said, I found my bug. If the problem still existed, I'm not sure how a semaphore would help me? A counting semaphore would do the job, but looking at 'man lockfile' I don't see that ability. Greg
On Thursday 06 January 2005 5:40 pm, Greg Freemyer wrote:
And the desire: I wish there were a simple way to create the partition as large as possible and not have to pass in the size in MEGS to parted. By using megs, I loosing a little bit of useable space at the end of the drive. (I know not enough to worry about.
Try sfdisk instead of parted. You can write the info for your desired
partitions into it's stdin. Each line represents one partition in the
following format:
<partition number> : start=
participants (3)
-
Greg Freemyer
-
James Oakley
-
Patrick Shanahan