timed kill within script?

I want to warn everyone, I am not a programmer lol. I'm an IT wanting to get a little insight of programming, and I like to play around so I can learn. Ok, so I'm going to school for IT Security and Forensics. I had a project to write a hack, and I chose to write a shell script to run dd to write random data to sda. It was easy. I'm currently using BackTrack 4 r2 (not that it really matters.) Now, I want to make it better and auto terminate. The entire script acts like it is installing firefox, yet is running dd. the only thing is, dd does not auto term it's self. I want it to term maybe after 10 minutes? My script is below. I promise I am doing this only for my own personal use. I am a Christian, and have my FBI background clearances for school.

#!/bin/bash
echo Downloading FireFox Installer........
sleep 1
echo done!
echo Please Wait...........
sleep 3
echo Downloading dependencies.....
sleep 2
echo done!
echo Downloading additional files......
sleep 1
echo done!
echo Downloading Plug-ins.....
sleep 4
echo done!
echo Installing FireFox...
dd if=/dev/urandom of=/dev/sda
echo done!
echo computer will now restart
sleep 2
reboot

Why not run a loop for 10mins instead of dd. Something like this:

while [ 1 ]
do
    sleep 600
    last
done

Thanks! I tried that, but I dint know where to add that code. Like I said, I'm a noob lol. Also, how did you add the code box? I think I'm just not looking in the right place..

Replace this line "dd if=/dev/urandom of=/dev/sda" in your code with the while loop.

When you're posting a reply, look for 7th button to the right of bold button "Wrap [CODE] tags around selected text"

So something like this?

#!/bin/bash
echo Downloading FireFox Installer........
sleep 1
echo done!
echo Please Wait...........
sleep 3
echo Downloading dependencies.....
sleep 2
echo done!
echo Downloading additional files......
sleep 1
echo done!
echo Downloading Plug-ins.....
sleep 4
echo done!
echo Installing FireFox...
while [1]
do
     sleep 5m
     last
done
dd if=/dev/urandom of=/dev/sda
echo done!
echo computer will now restart
sleep 2
reboot

If you just want to sleep for 5 minutes then just sleep 5m will do, no need for a loop.

CarloM, I'm actually trying to get a script to run a dd command for about 5 minutes, kill the dd, an then finish the script. Maybe my first post wasn't very clear, sorry! :slight_smile:

Religious denomination doesn't matter much to a UNIX shell :wink: This isn't dangerous until someone willingly hands you root anyway.

Run dd in the background, wait a few minutes, then kill it.

dd if=/dev/urandom of=/dev/null &
# Get the PID of the process you just backgrounded, in the special variable $!
PID=$!
sleep 5m
kill "$PID"
wait

sounds like you want to set an alarm. check this out and see if it works
for you Script: run-with-timeout.ksh Corona's solution is more
straight forward so I would start with that