Saturday, May 12, 2012

Solving "/bin/bash^M: bad interpreter: No such file or directory"

If you are getting errors like "/bin/bash^M: bad interpreter: No such file or directory", then I am a mind-reader and can say that you have edited this script on a Windows system. Error looks like:
# ./mysql_backup.sh
-bash: ./mysql_backup.sh: /bin/bash^M: bad interpreter: No such file or directory
You can solve this error by using "dos2unix" as:
# dos2unix mysql_backup.sh

Determine Directory Size In Linux with 'du'

'du' is an acronym for Disk Usage. So, if you want to find the size of a directory in Linux/Unix:
du <directory_name>
A more human-readable format can be generated using -h switch which outputs size with M,G and similar postfix.
du -h <directory_name>

Thursday, May 10, 2012

Check the progress of 'dd'

Even though I call 'dd' a disk destroyer, I have to use this regularly. Once, I had to copy a whole disk to another disk and was waiting for it to finish. Then, I found 'SIGUSR' signal that could be sent to a process to output some relevant information ('dd' in our case).

While 'dd' is running, open a new terminal. First let's get the PID:
# ps -A|grep dd
Then, do this:
# kill -USR1 <pid>
Now, see the terminal where 'dd' is running. You would get some details about the transfer progress. If you are really impatient, you can run this command every 20 seconds with 'watch':
watch -n 20 kill -USR1 <pid>

Convert openSUSE DVD ISO into USB image

To convert openSUSE 12.1 DVD ISO (64 Bit) to an ISO that can be dded"to a USB drive, do this:
# zypper in syslinux
# isohybrid openSUSE-12.1-DVD-x86_64.iso
Now, use SUSE Studio ImageWriter to write this ISO or dd to your usb drive.