Results 1 to 2 of 2

Thread: how do i run a script? I tried sudo bash.....

  1. #1

    Default how do i run a script? I tried sudo bash.....

    sen@sen-laptop:~$ dir
    image-usb-stick.sh Music Public usb-raw-image-file.raw Videos
    sen@sen-laptop:~$ sudo bash image-usb-stick.sh usb-raw-image-file.raw
    Available USB Disk Devices:
    device path not found
    device path not found
    device path not found
    device path not found
    /dev/N: sdb (stor_1022A
    stor\x201022A\x20\x20\x20\x20\x20\x20
    2136)
    device path not found
    device path not found
    Device node to image [/dev/N: sdb]:



    anybody know what I'm doing wrong
    My 2.0gb thumb-drive is plugged in but not mounted.
    Here's the script I'm trying to write the raw to the usb drive

    #!/bin/bash
    #
    # Script to image USB sticks in an easy and hopefully safe reassuring way
    # Aaron Bockover <abockover@novell.com>
    #

    function bail () {
    echo "Error: $@" 1>&2
    exit 1
    }

    function usage () {
    echo "Usage: $0 <usb-raw-image-file>" 1>&2
    exit 1
    }

    [[ $UID -eq 0 ]] || bail "You must be root"
    udevadm --version &>/dev/null || bail "Could not run udevadm"

    OPTION_IMAGE_FILE=$1
    [[ -z "$OPTION_IMAGE_FILE" ]] && usage
    [[ -e "$OPTION_IMAGE_FILE" ]] || bail "USB Raw Image file not found"

    FIRST_DEVICE=

    function list_usb_devices () {
    echo "Available USB Disk Devices:"

    for dev in $(/sbin/udevadm info --export-db | \
    awk '/^P:/{sub("^P:[[:space:]]*", "", $0); print}'); do
    if udevadm info --path="$dev" --query=all | grep -q ID_TYPE=disk; then
    if udevadm info --path="$dev" --query=all | grep -q ID_BUS=usb; then
    MODEL=$(udevadm info --path="$dev" --query=all | \
    awk -F= '/^E: ID_MODEL/{print $2}')
    ROOT=$(udevadm info --root)
    NODE=$(udevadm info --path="$dev" --query=all | \
    awk '/^N:/{sub("^N:[[:space:]]*", "", $0); print}')
    NODE="${ROOT}/${NODE}"

    if echo "$NODE" | grep -q "[0-9]$"; then
    continue
    fi

    if mount | grep -q "^${NODE}"; then
    echo " ${NODE} (${MODEL}) - MOUNTED"
    mount | grep "^${NODE}" | sed 's,type.*,,;s,^, ,'
    else
    echo " ${NODE} (${MODEL})"
    fi

    [[ -z "$FIRST_DEVICE" ]] && FIRST_DEVICE="$NODE"
    fi
    fi
    done

    [[ -z "$FIRST_DEVICE" ]] && return 1 || return 0
    }

    function unmount_device () {
    for mount in $(mount | grep "^${1}" | cut -f3 -d' '); do
    umount "$mount" || bail "Could not unmount ${mount} on ${1}"
    done
    }

    function image_device () {
    PROGRESS_FILE=$(mktemp)
    TOTAL_SIZE=$(stat -c%s "$2")
    [[ -e "$PROGRESS_FILE" ]] || bail "Could not create temp file"
    ( dd if="$2" of="$1" &>"$PROGRESS_FILE" &
    DD_PID=$!
    while ps -p $DD_PID &>/dev/null; do
    sleep 1
    kill -USR1 $DD_PID &>/dev/null
    COPIED=$(tail -n1 < "$PROGRESS_FILE" | cut -f1 -d' ')
    PERCENT=$(echo "" | \
    awk '{print int(('$COPIED'/'$TOTAL_SIZE') * 100)}')
    printf "\r${COPIED}/${TOTAL_SIZE} (%d%%) " $PERCENT
    done
    echo
    rm -f "$PROGRESS_FILE"
    ) || bail "Failed to image ${1}"
    }

    if ! list_usb_devices; then
    echo " No devices found."
    exit 1
    fi

    if [[ -z "$OPTION_DEVICE_NODE" ]]; then
    read -p "Device node to image [$FIRST_DEVICE]: " OPTION_DEVICE_NODE
    [[ -z "$OPTION_DEVICE_NODE" ]] && OPTION_DEVICE_NODE="$FIRST_DEVICE"
    fi

    [[ -e "$OPTION_DEVICE_NODE" ]] || \
    bail "Device node $OPTION_DEVICE_NODE not found"

    if mount | grep -q "^${OPTION_DEVICE_NODE}"; then
    if [[ -z "$OPTION_UNMOUNT" ]]; then
    read -p \
    "Device ${OPTION_DEVICE_NODE} is mounted. Unmount it? (Y/N) [Y]: " \
    OPTION_UNMOUNT
    [[ -z "$OPTION_UNMOUNT" ]] && OPTION_UNMOUNT="y"
    fi

    if [[ "$OPTION_UNMOUNT" = "y" || "$OPTION_UNMOUNT" = "Y" ]]; then
    echo "Unmounting ${OPTION_DEVICE_NODE}..."
    unmount_device "$OPTION_DEVICE_NODE"
    else
    bail "Cannot image ${OPTION_DEVICE_NODE} without unmounting it"
    fi
    fi

    echo "Imaging ${OPTION_DEVICE_NODE} with $(basename ${OPTION_IMAGE_FILE})..."
    image_device "${OPTION_DEVICE_NODE}" "${OPTION_IMAGE_FILE}"

    echo "Syncing..."
    sync

    echo "Ejecting..."
    eject "${OPTION_DEVICE_NODE}"

    echo "Done."

  2. #2

    Default Re: how do i run a script? I tried sudo bash.....

    I don't know anything about that script, but the general way is to execute it by name including extension, starting with its path (unless it's already in your $PATH). Its path can be relative, but it must be explicit, so if you're executing my.script.sh from the same directory you'd put

    Code:
    ./my.script.sh arguments
    (because "." means "this directory" and "/" means "relative to" whatever precedes it (if nothing precedes it it means root of the present file hierarchy))

    It has to be executable, so you might need to "chmod +x my.script.sh" first, which, depending on where it is, may need to be run as root.

    This may not help at all - I'm new at this

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •