You are not logged in.

#1 2016-01-13 19:01:05

jsalk
Member
Registered: 2015-06-20
Posts: 18

bash file cannot find /dev/sdb

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

#2 2016-01-13 19:06:13

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: bash file cannot find /dev/sdb

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.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2016-01-13 19:36:31

jsalk
Member
Registered: 2015-06-20
Posts: 18

Re: bash file cannot find /dev/sdb

Trilby wrote:
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

#4 2016-01-13 21:31:10

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: bash file cannot find /dev/sdb

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)


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

Board footer

Powered by FluxBB