I would like to write a script file that contains these commands run as root
OS is Fedora 13 I686mkdir /mnt/clone
mount /dev/sdb1 /mnt/clone
dd if=/mnt/clone/clone.dd of=/dev/sda bs=8192 conv=sync,noerrorHow 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.
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
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?
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.