#753573 parted: please allow to read script commands from stdin or a file

Package:
parted
Source:
parted
Description:
disk partition manipulator
Submitter:
Enrico Zini
Date:
2014-07-20 00:15:09 UTC
Severity:
wishlist
#753573#5
Date:
2014-07-03 08:31:02 UTC
From:
To:
Hello,

thank you for packaging parted.

I currently have this in a deploy script:

  DISK=`find_disk`
  while read -r cmd; do parted -s -a optimal $DISK $cmd; done < commands.txt

that while loop works around parted only accepting script commands on
the command line. I wish I could do this:

  DISK=`find_disk`
  parted -s -a optimal $DISK read commands.txt

or this:

  DISK=`find_disk`
  compute_parted_commands | parted -s -a optimal $DISK read -

I understand that running each command in its own invocation makes it
possible to know which command exactly failed. In my case, though, I
work on an all-or-nothing situation: either the disk ends up partitioned
how we need it, or the installation procedure alarms[1] and halts.


Enrico

[1] it really does: it even plays a morse code SOS on the PC speaker :)

#753573#10
Date:
2014-07-19 23:58:12 UTC
From:
To:
Does it help to know (as I don't think it's well-documented) that all
parted commands apart from "help" can unambiguously determine when their
arguments end?  "parted -s" actually just works by popping a
command name from the command line, having that command pop arguments
until it's finished, popping another command name if possible, and
repeating until it runs out of words.  So, for example, you can do this:

  parted -s $DISK print unit s print

... and that's parsed as:

  print
  unit s
  print

This is a bit weird and so doesn't necessarily obviate your request, of
course, but it should let you just do this or some nearby variation:

  DISK=`find_disk`
  compute_parted_commands | xargs parted -s -a optimal $DISK

Cheers,

#753573#15
Date:
2014-07-20 00:13:32 UTC
From:
To:
In fact I now see that this is documented in "info parted", under
"Running Parted".  So I think you can safely rely on this.