Shell Script to invoke DD command

November 30, 2010 at 06:10:33
Specs: Fedora 11 686
I would like to write a script file that contains these commands run as root
OS is Fedora 13 I686

mkdir /mnt/clone
mount /dev/sdb1 /mnt/clone
dd if=/mnt/clone/clone.dd of=/dev/sda bs=8192 conv=sync,noerror

How would i start the script?

I dont understand all the bin/bash

Also at the end of the shell script could i somehow make it reboot and or report any errors to a log file of some sort

Please advise.


See More: Shell Script to invoke DD command

Report •

#1
November 30, 2010 at 16:17:27
You execute the script by either prepending ./ to the file name (you'll also have to mark it as executable, or by running sh filename.

Here is a pair of scripts that should do this for you. The reason there are two so 1.)you don't have to manually start a root shell or append sudo and 2.)aren't dropped to a root shell after the script is done.

#!/bin/bash
#You can call this script whatever name you like. The script called by the #command below needs to be whatever you call the second script. Oh, and you #don't need to include my comments here if you don't need them.

su -c ./script2.sh

#!/bin/bash
###This is where most of the magic happens.
##Store date in variable for log formatting
DATE=$(date +"%A, %B %e, %Y %r")

##Creates the directory and pipes text output to log file in /var/log

echo "///Log entry for $DATE" >> /var/log/command.log
echo "//mkdir output text" >> /var/log/command.log
mkdir /mnt/clone >> /var/log/command.log 2>&1

##Mounts partition and pipes text output to log file in /var/log

echo "//mount output text" >> /var/log/command.log
mount /dev/sdb1 /mnt/clone > /var/log/command.log 2>&1

##Runs dd and pipes text output to log file in /var/log

echo "//dd output text" >> /var/log/command.log"
dd if=/mnt/clone/clone.dd of=/dev/sda bs=8192 conv=sync,noerror > /var/log/command.log 2>&1


Report •

#2
December 1, 2010 at 05:58:04
Thanks alot! I am just backing up my cloning drive before testing but it looks great. I am running Fedora off of a USB stick with this script saved to the live user.. Will this effect the logging? Will the logs save to the usb stick or be deleted when shutting off the live machine?

Report •

#3
December 1, 2010 at 09:38:05
The location where I told it to put the logs would normally be lost when the computer was shut down from a Live system. I've never used a Fedora LiveUSB before, but many Ubuntu LiveCD instructions provide for making a "persistent" storage partition on the USB drive as well. You would just need to change the location where the logs were stored, or else mount /var somewhere else.

Report •
Related Solutions


Ask Question