LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-02-2016, 04:15 PM   #16
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142

Quote:
Originally Posted by Pandapoke View Post
Now i get the error message "dd: failed to open ‘~/Downloads/OS/Linux/Dists/mint173c.iso’: No such file or directory
0B 0:00:00 [ 0B/s] [<=> " but it is the right location.
That's because you're running sudo. Sudo switches to root, and once you're running as root, "~" points to /root/ instead of /home/user/. If you use $HOME instead, it will be expanded when calling the script and should work.
 
Old 03-02-2016, 04:34 PM   #17
brokenleg
LQ Newbie
 
Registered: Mar 2016
Posts: 5

Rep: Reputation: Disabled
Make sure the endline format is unix and not windows.
 
Old 03-03-2016, 12:42 AM   #18
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
you can try to use dcfldd instead of dd, that will make your script better (pv is built-in)
 
Old 03-03-2016, 03:33 AM   #19
Pandapoke
LQ Newbie
 
Registered: Mar 2016
Posts: 13

Original Poster
Rep: Reputation: Disabled
Were i the code should i put

Quote:
echo "Going to format $device, are you sure (y/N)?"
read ans
if [[ "$ans" != "y" && "$ans" != "Y" ]]; then
echo "Exiting on user cancel"
exit 3
fi

size=$(fdisk -l $device | grep bytes | head -n 1 | awk '{print $5}')
sizeGB=$(echo "$size / 1073741824" | bc -l | xargs printf "%7.2f\n")
echo "Detected a $sizeGB GB device at $device, is this correct (y/N)?"
read ans
if [[ "$ans" != "y" && "$ans" != "Y" ]]; then
echo "Exiting on user cancel"
exit 3
fi
And dont i need bs in the dd command?

Quote:
4) sudo dd if=$iso of=/dev/$device
echo "Burn done"
exit ;;

mvh
 
Old 03-03-2016, 03:36 AM   #20
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
$sizeGB is incorrect, you do not have variable named sizeGB defined. Use ${size}GB instead
Otherwise I do not really understand what is your current problem
 
Old 03-03-2016, 03:48 AM   #21
Pandapoke
LQ Newbie
 
Registered: Mar 2016
Posts: 13

Original Poster
Rep: Reputation: Disabled
Thanks for all the help

where should i put this code in mine?


Code:
echo "Going to format $device, are you sure (y/N)?"
read ans
if [[ "$ans" != "y" && "$ans" != "Y" ]]; then
   echo "Exiting on user cancel"
   exit 3
fi

size=$(fdisk -l $device | grep bytes | head -n 1 | awk '{print $5}')
sizeGB=$(echo "$size / 1073741824" | bc -l | xargs printf "%7.2f\n")
echo "Detected a $sizeGB GB device at $device, is this correct (y/N)?"
read ans
if [[ "$ans" != "y" && "$ans" != "Y" ]]; then
   echo "Exiting on user cancel"
   exit 3
fi

And does not dd need bs command?

Quote:
Originally Posted by michaelk View Post
Code:
sudo "dd if=$iso | pv | of=/dev/$device bs=$speed"
Your mixing commands.

Go back to your original code then add the fancy stuff. Try this:
Code:
4) sudo dd if=$iso of=/dev/$device 
   echo "Burn done" 
   exit ;;

thanks
mvh
 
Old 03-03-2016, 03:52 AM   #22
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
"dd if=$iso | pv | of=/dev/$device bs=$speed" is syntactically incorrect. It looks like 3 commands:
Code:
dd if=$iso
pv
of=/dev/$device bs=$speed
chained together with pipes, but of=/dev/$device bs=$speed is not a valid command but the second half of the first one (dd).
You need to understand it is simply wrong, useless.
 
Old 03-03-2016, 06:33 AM   #23
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,680

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
Code:
4) echo "Going to format $device, are you sure (y/N)?"
read ans
if [[ "$ans" != "y" && "$ans" != "Y" ]]; then
   echo "Exiting on user cancel"
   exit 3
fi
...
The default block size is 512 bytes which is typically the default for flash drives. So bs isn't absolutely necessary. You also want to make sure to unmount the device if mounted.
 
Old 03-03-2016, 08:02 AM   #24
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Quote:
Originally Posted by Pandapoke View Post
Thanks for all the help

where should i put this code in mine?


Code:
echo "Going to format $device, are you sure (y/N)?"
read ans
if [[ "$ans" != "y" && "$ans" != "Y" ]]; then
   echo "Exiting on user cancel"
   exit 3
fi

size=$(fdisk -l $device | grep bytes | head -n 1 | awk '{print $5}')
sizeGB=$(echo "$size / 1073741824" | bc -l | xargs printf "%7.2f\n")
echo "Detected a $sizeGB GB device at $device, is this correct (y/N)?"
read ans
if [[ "$ans" != "y" && "$ans" != "Y" ]]; then
   echo "Exiting on user cancel"
   exit 3
fi

And does not dd need bs command?




thanks
mvh
No, the bs flag just changes the default from 512 bytes.

As for where to put the confirmation questions, that should be obvious...somewhere between when the user enters the device name and where you blow it away with dd.

Honestly, this thread has done nothing but made it ABUNDANTLY clear you are not ready to dd inside a script. Put this on the back burner until you gain more scripting experience, I'm serious. You're not ready to automate any command that requires sudo, most certainly not dd. It's not meant as an insult, I'm just trying to keep you from destroying your system. dd doesn't have the nickname "disk destroyer" for nothing.
 
Old 03-03-2016, 02:56 PM   #25
Pandapoke
LQ Newbie
 
Registered: Mar 2016
Posts: 13

Original Poster
Rep: Reputation: Disabled
I have most of the code figured out execpt the dd command itself

Code:
#!/bin/bash
#set -vx
speed=512K
while true
do

    clear
    echo "============================="
    echo "    Burning menu using dd    "
    echo "============================="
    echo "Enter 1 for full path to iso."
    echo "Enter 2 for media"
    echo "Enter 3 to set bs speed 512K default"
    echo "Enter 4 to execite dd command "
    echo "Enter q to exit q:"
    echo -e "\n"
    echo -e "Enter your choice \c"
    read -r choice
    case "$choice" in
        q) exit ;;
        1) echo -e "Enter path to iso \c"
           read -r iso ;;
        2) echo -e "Enter device"
           read -r device ;;
        3) echo -e "Enter bs speed \c"
           read -r speed ;;
        4) echo "Going to format $device, are you sure (y/N)?"
           read ans
        if [[ "&ans" != "y" && "&ans" != "Y" ]]; then
            echo "Clearing screen"
            sleep 3
            clear
            "dd if=$iso of=/dev/$device bs=$speed"
            echo "Burning please wait"
            sleep 30
        fi
    esac
done
but when i execture "4" to use dd command i get this output
Quote:
./burn2.sh: line 33: dd if=~/Downloads/OS/Linux/Dists/m.img of=/dev/sdb1 bs=512K: No such file or directory
There is such a file and i have tried with other iso:s and img:s

can anyone help a beginner?
mvh

Thanks in advance.
 
Old 03-03-2016, 03:10 PM   #26
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by Pandapoke View Post
I have most of the code figured out execpt the dd command itself

Code:
#!/bin/bash
#set -vx
speed=512K
while true
do

    clear
    echo "============================="
    echo "    Burning menu using dd    "
    echo "============================="
    echo "Enter 1 for full path to iso."
    echo "Enter 2 for media"
    echo "Enter 3 to set bs speed 512K default"
    echo "Enter 4 to execite dd command "
    echo "Enter q to exit q:"
    echo -e "\n"
    echo -e "Enter your choice \c"
    read -r choice
    case "$choice" in
        q) exit ;;
        1) echo -e "Enter path to iso \c"
           read -r iso ;;
        2) echo -e "Enter device"
           read -r device ;;
        3) echo -e "Enter bs speed \c"
           read -r speed ;;
        4) echo "Going to format $device, are you sure (y/N)?"
           read ans
        if [[ "&ans" != "y" && "&ans" != "Y" ]]; then
            echo "Clearing screen"
            sleep 3
            clear
            "dd if=$iso of=/dev/$device bs=$speed"
            echo "Burning please wait"
            sleep 30
        fi
    esac
done
but when i execture "4" to use dd command i get this output


There is such a file and i have tried with other iso:s and img:s

can anyone help a beginner?
mvh

Thanks in advance.
I think you've been told a few times that you need to use sudo for the dd command. Or be root. In addition to that, you also should not use $HOME or the ~ notation because it will point to /home/root, instead you should save the full path into another variable, such as START_DIR=/home/wherever/Downloads/etc/etc and then use that variable $START_DIR.
 
Old 03-03-2016, 04:08 PM   #27
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Quote:
Originally Posted by rtmistler View Post
I think you've been told a few times that you need to use sudo for the dd command. Or be root. In addition to that, you also should not use $HOME or the ~ notation because it will point to /home/root, instead you should save the full path into another variable, such as START_DIR=/home/wherever/Downloads/etc/etc and then use that variable $START_DIR.
$HOME should be fine, because the variable substitution will occur before sudo gets a hold of the argument.
 
1 members found this post helpful.
Old 03-03-2016, 04:19 PM   #28
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by suicidaleggroll View Post
$HOME should be fine, because the variable substitution will occur before sudo gets a hold of the argument.
I concede that point. I personally prefer to be exact. Then again I also suggested not "firing away" with a command like dd and instead outputting a summary and allow the operator to be cautious in the event that they may be heading for destruction of their boot drive of something.
 
Old 03-04-2016, 12:33 AM   #29
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
was already: http://www.linuxquestions.org/questi...7/#post5508971

and you will see how your input/variables were handled by the script
 
Old 03-04-2016, 02:33 AM   #30
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Use '$ans', not '&ans'
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Best Scripting Language for beginner : Bash vs Python vs Perl sriram91 Linux - Newbie 10 02-28-2015 12:38 PM
[SOLVED] Bash beginner, please help. Fred_mike Programming 4 06-21-2011 09:38 PM
Beginner question, Bash-script - date kickarzt Programming 15 03-10-2010 12:18 PM
Bash substitution -- Fairly beginner stuff! ipguru99 Programming 4 01-01-2008 04:31 PM
What is the best book for a beginner to learn his way 'round BASH??? Fabyfakid Linux - Newbie 8 10-15-2004 11:04 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration