You are not logged in.
Pages: 1
I am trying to use a bash file to partition /dev/sdb. When I enter "fdisk /dev/sdb" in a terminal, I have no problem. But I would like to automate this function using the following bash file:
#!/bin/bash
# partition the drive
sed -e 's/\t\([\+0-9a-zA-Z]*\)[ \t].*/\1/' << EOF | fdisk /dev/sdb
o # clear the in memory partition table
n # new partition
p # primary partition
1 # partition number 1
# default - start at beginning of disk
# default - end at end of disk
p # print the in-memory partition table
w # write the partition table
EOF
Running "/bin/bash /var/www/shell/drive-partition.sh" from a terminal command prompt, I get this result:
Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
: No such file or directory
Running it in a web page using "exec('/bin/bash /var/www/shell/drive-partition.sh 2>&1', $retArr, $retVal);" in a php file, I get this output:
fdisk: cannot open /dev/sdb : No such file or directory
1
finished
I'm curious as to why fdisk can find /dev/sdb when running directly and cannot in a bash file. Any ideas would be appreciated.
- Jim
Offline
I'm curious as to why fdisk can find /dev/sdb when running directly and cannot in a bash file.
You just showed that it can, just the commands entered don't work.
You did show that /dev/sdb is not accessible from a php script. This is not particularly surprising to me.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
jsalk wrote:I'm curious as to why fdisk can find /dev/sdb when running directly and cannot in a bash file.
You just showed that it can, just the commands entered don't work.
You did show that /dev/sdb is not accessible from a php script. This is not particularly surprising to me.
Thanks.
It seems to me that I also showed that it is not currently accessible from a bash script. The problem is, I have to use one to enter all the fdisk commands.
Some time ago, I saw a system that formatted a drive via a web script (I wish I could recall where it was). So I would think it is possible. I just don't know why the bash script cannot find the drive.
- Jim
Offline
As you've discovered fdisk doesn't like being run from a script. That's the job of sfdisk (scriptable fdisk).
man sfdisk
Last edited by Slithery (2016-01-14 17:49:15)
Offline
Pages: 1