ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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
$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
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
"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.
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.
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.
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.
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.
$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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.