You are not logged in.
I was writing a secure-delete script (just felt like it ) and was wondering if there was any way to prevent a for-loop (in bash) from forking the processes within. I have a dd command inside the for loop. Here's the script:
#!/bin/bash
SIZE=$(ls -la | grep $1 | sed 's/-.*chiraag chiraag //' | sed 's/[A-Z].*//' | sed 's/\ //');
#echo $SIZE
for i in {1..35}
do
dd if=/dev/urandom of=$1 count=$(($SIZE / 2)) bs=2 > /dev/null 2>&1&;
done
#for i in {1..1000}
#do
dd if=/dev/zero of=$1 count=$(($SIZE / 2)) bs=2 > /dev/null 2>&1&
#done
rm -rf $1
I decided to run the zero function only once because even if people recover the file, it will be junk
Thanks in advance!
- Chaanakya
Last edited by chaanakya (2011-09-07 21:28:13)
Check out Musik - an easy-to-use text-to-music converter!
Join SpiderOak using this link and get an extra 1 GB free: https://spideroak.com/download/referral … 660e787ff1
Offline
So you don't want dd to have it's own PID? I don't know where to start, how about you describe step by step what happens (system-wise) line by line in your program (and in relation to bash) and I shout stop? :-D
dd is not a function/procedure/object, dd is a program. If something should run inside bash without being forked, it must be something bash can interprete. Since bash does not interprete dd, but simply calls it in /bin/dd to accept the given parameters.
So the answer is: Reimplement dd in bash. What's the matter with the fork here?
I'm so meta, even this acronym
Offline
This isn't answering your question at all, but you can put those three sed calls together and only call it once, saving two subshells:
sed 's/-.*chiraag chiraag //' | sed 's/[A-Z].*//' | sed 's/\ //'
ie
sed 's/-.*chiraag chiraag //;s/[A-Z].*//;s/\ //'
Also, I can't find a reference to that "i" in the do loop:
for i in {1..35}
do
dd if=/dev/urandom of=$1 count=$(($SIZE / 2)) bs=2 > /dev/null 2>&1&;
done
Last edited by johnraff (2011-09-07 16:47:16)
John
--------------------
( a boring Japan blog , Japan Links, idle twitterings and GitStuff )
#! forum moderator BunsenLabs
Offline
Yeah...the i is only there as the index number - I don't actually need it in my command. I just want to run the dd command 35 times, and this is the easiest way to do it (I think)...is there an easier way which would wait for the first dd to complete before calling it again as the second iteration?
Check out Musik - an easy-to-use text-to-music converter!
Join SpiderOak using this link and get an extra 1 GB free: https://spideroak.com/download/referral … 660e787ff1
Offline
is there an easier way which would wait for the first dd to complete before calling it again as the second iteration?
while-loop maybe?
Offline
But would the while-loop wait? That's what I'm not sure of, and I surely do *not* want to have this thing nearly fork-bomb my comp again (although...35 writes isn't a lot, so it shouldn't hang up my laptop that badly...)
Check out Musik - an easy-to-use text-to-music converter!
Join SpiderOak using this link and get an extra 1 GB free: https://spideroak.com/download/referral … 660e787ff1
Offline
Awebb: every time the for-loop executes, a new dd process is spawned. This means that at one point, there were 1000 dd processes all writing to the same file...not a pretty sight.... the whole computer froze and I got errors with Resource Temporarily Unavailable etc. I'm just trying to see if I can avoid that again...admittedly, with 35 passes, it shouldn't actually matter - there won't be many processes. However, it would still be nice if I could get each iteration to wait until the previous iteration had finished writing to the file.
Thanks in advance!
- Chaanakya
Check out Musik - an easy-to-use text-to-music converter!
Join SpiderOak using this link and get an extra 1 GB free: https://spideroak.com/download/referral … 660e787ff1
Offline
Okay...wow...I was being *really* stupid...I put an "&" at the end!!!!! I should have put a ";". I wanted to hide all output, so I used a part of a script I had made earlier...neglected to see that I had an "&" at the end...
Well...I guess the topic's closed!
Check out Musik - an easy-to-use text-to-music converter!
Join SpiderOak using this link and get an extra 1 GB free: https://spideroak.com/download/referral … 660e787ff1
Offline
Haha, assuming the question was stupid, I didn't look at the code closely enough to see the missing semikolon. "Never assume..." :-D
But you had me for a moment. Wildly forking dd's... nah :-P
I'm so meta, even this acronym
Offline
Whoo-hoo - you caught us all out there
(actually even a semicolon isn't needed if you've got a linebreak)
John
--------------------
( a boring Japan blog , Japan Links, idle twitterings and GitStuff )
#! forum moderator BunsenLabs
Offline
Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.
Server: acrobat