You are not logged in.

#1 2009-06-14 06:19:24

sa
Member
From: boston ma
Registered: 2008-05-23
Posts: 127
Website

writing a script to automate dd?

can i make a bash script to do something like this? i also know a little bit of C, but it seems like bash script might make more sense for the job.

i'm trying to make a script that would allow the user to enter a variable, and then use that variable to execute dd. so for instance, i want to make and ISO file named 'whatever.iso", so i could have the user type in "whatever", and it would execute "dd if=/dev/sr0 of=whatever.iso blah blah lots of options". what would be the best way to do something like this?

Offline

#2 2009-06-14 06:38:31

.:B:.
Forum Fellow
Registered: 2006-11-26
Posts: 5,819
Website

Re: writing a script to automate dd?

Your arguments start counting at 1 (the command itself being $0). So you could do

#!/bin/bash

dd if="$1" of="$2"

That's the basic version. You could also provide a help function that not only displays if --help is called e.g. but also if not enough parameters are given.


Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy

Offline

#3 2009-06-14 08:11:57

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,231
Website

Re: writing a script to automate dd?

B has given you a good start... Read up on bash 'if' statements and make sure you put some tests in there to make sure the user hasn't entered "/dev/sda" as argument #2, or you'll be in trouble(!)

Offline

#4 2009-06-14 10:28:06

moljac024
Member
From: Serbia
Registered: 2008-01-29
Posts: 2,676

Re: writing a script to automate dd?

And be extra careful with those scripts! big_smile


The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...

Offline

Board footer

Powered by FluxBB